EmailMessage { public void sendEmail() throws MessagingException { checkSettings(); final Properties props = new Properties(); if (this._usesAuth) { props.put("mail.smtp.auth", "true"); props.put("mail.user", this._mailUser); props.put("mail.password", this._mailPassword); } else { props.put("mail.smtp.auth", "false"); } props.put("mail.smtp.host", this._mailHost); props.put("mail.smtp.port", this._mailPort); props.put("mail.smtp.timeout", _mailTimeout); props.put("mail.smtp.connectiontimeout", _connectionTimeout); props.put("mail.smtp.starttls.enable", this._tls); props.put("mail.smtp.ssl.trust", this._mailHost); final JavaxMailSender sender = this.creator.createSender(props); final Message message = sender.createMessage(); final InternetAddress from = new InternetAddress(this._fromAddress, false); message.setFrom(from); for (final String toAddr : this._toAddress) { message.addRecipient(Message.RecipientType.TO, new InternetAddress( toAddr, false)); } message.setSubject(this._subject); message.setSentDate(new Date()); if (this._attachments.size() > 0) { final MimeMultipart multipart = this._enableAttachementEmbedment ? new MimeMultipart("related") : new MimeMultipart(); final BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(this._body.toString(), this._mimeType); multipart.addBodyPart(messageBodyPart); for (final BodyPart part : this._attachments) { multipart.addBodyPart(part); } message.setContent(multipart); } else { message.setContent(this._body.toString(), this._mimeType); } retryConnectToSMTPServer(sender); retrySendMessage(sender, message); sender.close(); } EmailMessage(final String host, final int port, final String user, final String password,
      final EmailMessageCreator creator); static void setTimeout(final int timeoutMillis); static void setConnectionTimeout(final int timeoutMillis); static void setTotalAttachmentMaxSize(final long sizeInBytes); EmailMessage enableAttachementEmbedment(final boolean toEnable); EmailMessage addAllToAddress(final Collection<? extends String> addresses); EmailMessage addToAddress(final String address); EmailMessage setFromAddress(final String fromAddress); EmailMessage setTLS(final String tls); EmailMessage setAuth(final boolean auth); EmailMessage addAttachment(final File file); EmailMessage addAttachment(final String attachmentName, final File file); EmailMessage addAttachment(final String attachmentName, final InputStream stream); void sendEmail(); void setBody(final String body, final String mimeType); EmailMessage setMimeType(final String mimeType); EmailMessage println(final Object str); String getBody(); void setBody(final String body); String getSubject(); EmailMessage setSubject(final String subject); int getMailPort();  }
@Test public void testSendEmail() throws Exception { this.em.setTLS("true"); this.em.addToAddress(this.toAddr); this.em.setFromAddress(this.sender); this.em.setSubject("azkaban test email"); this.em.setBody("azkaban test email"); this.em.sendEmail(); verify(this.mimeMessage).addRecipient(RecipientType.TO, this.addresses[0]); verify(this.mailSender).sendMessage(this.mimeMessage, this.addresses); }