Page 1 of 1

Sending Email

PostPosted: Wed Mar 27, 2019 5:56 pm
by SBarnes
How can you send an email from Jiwa with an attachment without needing to show the email form?

Re: Sending Email

PostPosted: Wed Mar 27, 2019 6:54 pm
by Mike.Sheen
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.

Re: Sending Email  Topic is solved

PostPosted: Thu Mar 28, 2019 8:51 am
by SBarnes
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();