Table of contents
No headings in the article.
This blog is about sending the custom emails via mirth without using the normal SMTP sender. This feature can e very beneficial when you want to loop through contents and send the email accordingly.
var email = null;
email = new Packages.org.apache.commons.mail.HtmlEmail();
email.setHostName(“host-name.net”);
email.setSmtpPort(‘your-smtp-port’);
email.setAuthenticator(new Packages.org.apache.commons.mail.DefaultAuthenticator(‘authorization-email@youremail.com’, ‘your-email-password’));
email.setSSLOnConnect(true);
// List of people who should receive the email
email.addTo(“send-email-to-this-mail@email.com”);
//email.addTo(“send-to-another-email@email.com”);
//email.addTo(“send-to-another-email@email.com”)
email.setFrom(‘sender-email-from-address@email.com’, ‘password’);
email.setSubject(“TEST ABCD”);
// set the html message
email.setHtmlMsg(“TEST”);
// set the alternative message
email.setTextMsg(“Your email client does not support HTML messages”);
var pdfBytes = FileUtil.readBytes(‘Your-PDF-Path’);
var bads = new Packages.org.apache.commons.mail.ByteArrayDataSource(pdfBytes, “application/pdf”);
//add the attachment
email.attach(bads,fileSystem.pdf, $(‘reason’),Packages.org.apache.commons.mail.EmailAttachment.ATTACHMENT);
// Send email
email.send();