public void sendMessages() throws MessagingException {
            Transport transport = null;
            try {
                URLName url = new URLName("smtp", host, port, "", username, password);
                if (session == null) {
                    createSession();
                }
                transport = new com.sun.mail.smtp.SMTPTransport(session, url);
                transport.connect(host, port, username, password);
                for (MimeMessage message : messages) {
                    // Attempt to send message, but catch exceptions caused by invalid
                    // addresses so that other messages can continue to be sent.
                    try {
                        transport.sendMessage(message,
                            message.getRecipients(MimeMessage.RecipientType.TO));
                    }
                    catch (AddressException | SendFailedException ae) {
                        Log.error(ae.getMessage(), ae);
                    }
                }
            }
            finally {
                if (transport != null) {
                    try {
                        transport.close();
                    }
                    catch (MessagingException e) { /* ignore */ }
                }
            }
        }
Task to send one or more emails via the SMTP server.
xmppserver/src/main/java/org/jivesoftware/util/EmailService.java