Sending attachment to the e-mail

Hi
The e-mail sending process in CUBA looks straight forward and simple to me which is very good. Thanks for this great tool.
Now I want to send e-mail with attachment of a document created on the fly. e.g. When an Invoice is processed, the invoice report document will be created and sent as an attachment of the e-mail to the customer. Thanks for your help.

1 Like

I hope what I have explained above is possible in CUBA, it would be good you can provide a little more info in the documentation to explain it in addition to what is already explained.

Hi Mortoza,
You have probably read this section: Sending Emails - CUBA Platform. Developer’s Manual. If you need to send attachments, create an appropriate EmailAttachment object and pass it to the EmailInfo constructor:

File attachment


byte[] pdfBytes = new byte[]{1, 2, 3, 4, 6};
String fileName = "invoice.pdf";
EmailAttachment pdfAttach = new EmailAttachment(pdfBytes, fileName);

EmailInfo myInfo = new EmailInfo("test@example.com", "Test", null, "Test", pdfAttach);

Inline image attachment


byte[] imageBytes = new byte[]{1, 2, 3, 4, 5};
String fileName = "logo.png";
EmailAttachment imageAttach = new EmailAttachment(imageBytes, fileName, "logo");

EmailInfo myInfo = new EmailInfo("test@example.com", "Test", null, "Test", imageAttach);

Text attachment


String attachmentText = "Test Attachment Text";
EmailAttachment textAttach = EmailAttachment.createTextAttachment(attachmentText, "ISO-8859-1", "test.txt");

EmailInfo myInfo = new EmailInfo("test@example.com", "Test", null, "Test", textAttach);

Hope this helps.

1 Like

Hi Konstantin
When i want to generate a report file before it is attached, how do you suggest i should create on the fly (send parameter based on invoice selected (row selected in the table)) and the referred the invoice file in your code below?


byte[] pdfBytes = new byte[]{1, 2, 3, 4, 6};
String fileName = "invoice.pdf";
EmailAttachment pdfAttach = new EmailAttachment(pdfBytes, fileName);

Hi,
The sample project which illustrates how to send reports by email is attached.

The generated report file may be sent by email as below:


ReportOutputDocument outputDocument = reportService.createReport(targetreport, reportParams);
EmailAttachement emailAttach =  new EmailAttachment(outputDocument.getContent(), fileName);

SendReportByEmail.zip (45.2K)

2 Likes

Currently I can’t get yarg imported correctly. I’m searching for a solution, but in the meantime, can you tell me what I could use instead of “ReportOutputDocument” to get the report and add it to an email?

Solved. Not sure how, but I got it going.

Hi,
i would be test mail Jmx consplve>Emailer>testsendmail.it try to mannully (or) send to auto generation.