Sending Email  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Sending Email

Postby SBarnes » Wed Mar 27, 2019 5:56 pm

How can you send an email from Jiwa with an attachment without needing to show the email form?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Sending Email

Postby Mike.Sheen » Wed Mar 27, 2019 6:54 pm

SBarnes wrote:How can you send an email from Jiwa with an attachment without needing to show the email form?


We have some sample plugins which do this with the email form, but doing it without a form is pretty much the same - as the form is just a UI representation of the business logic - the plugins talk to the Email business logic for all the work. "Email Plugin" and "Email Report" are two examples - crack those open and you'll see how it's done.

Just create an instance of the JiwaEmail business logic object using our Manager.BusinessLogicFactory and copy paste the required bits.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Sending Email  Topic is solved

Postby SBarnes » Thu Mar 28, 2019 8:51 am

Just for completeness here is the code

Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.JiwaEmail.EmailMessage emessage = this.Manager.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaApplication.JiwaEmail.EmailMessage>(null);
               
             emessage.CreateNew();
            emessage.EmailSubject = string.Format("Attached {0}",filename);
            
            JiwaFinancials.Jiwa.JiwaApplication.Documents.Document documentAttachment = this.Manager.CollectionItemFactory.CreateCollectionItem<JiwaFinancials.Jiwa.JiwaApplication.Documents.Document>();
            documentAttachment.PhysicalFileName = newFile;
            
            using (System.IO.FileStream stream = new System.IO.FileStream(newFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
               using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream))
               {
                  documentAttachment.FileBinary = reader.ReadBytes((int)stream.Length);
               }
            }
            emessage.EmailFrom = this.Manager.Staff.EmailAddress;
            emessage.EmailTo = this.Manager.Staff.EmailAddress;
            emessage.Attachments.Add(documentAttachment);   
            emessage.Save();
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests