use of com.axway.ats.log.report.exceptions.MailReportSendException in project ats-framework by Axway.
the class MailReportSender method send.
/**
* Email the report
*/
public void send() {
log.info("Sending log mail report");
// get the info needed for sending a mail
ReportConfigurator reportConfigurator = ReportConfigurator.getInstance();
String smtpServerName = reportConfigurator.getSmtpServerName();
String smtpServerPort = reportConfigurator.getSmtpServerPort();
String[] addressesTo = reportConfigurator.getAddressesTo();
String[] addressesCc = reportConfigurator.getAddressesCc();
String[] addressesBcc = reportConfigurator.getAddressesBcc();
String addressFrom = reportConfigurator.getAddressFrom();
// Attaching to default Session
Properties mailProperties = new Properties();
mailProperties.put("mail.smtp.host", smtpServerName);
mailProperties.put("mail.smtp.port", smtpServerPort);
Session session = Session.getDefaultInstance(mailProperties);
Message msg = new MimeMessage(session);
String errMsg = "Error creating mail object";
try {
// mail addresses
msg.setFrom(new InternetAddress(addressFrom));
msg.setRecipients(Message.RecipientType.TO, transformAdresses(addressesTo));
msg.setRecipients(Message.RecipientType.CC, transformAdresses(addressesCc));
msg.setRecipients(Message.RecipientType.BCC, transformAdresses(addressesBcc));
// mail subject
msg.setSubject(subject);
// mail content
msg.setContent(body, "text/html");
// other header information
msg.setSentDate(new Date());
} catch (AddressException e) {
throw new MailReportSendException(errMsg, e);
} catch (MessagingException e) {
throw new MailReportSendException(errMsg, e);
}
// send the message
errMsg = "Error sending mail";
try {
Transport.send(msg);
} catch (MessagingException e) {
throw new MailReportSendException(errMsg, e);
}
log.info("Log mail report sent ok");
}
Aggregations