Search in sources :

Example 41 with Transport

use of javax.mail.Transport in project jmeter by apache.

the class SendMailCommand method execute.

/**
     * Sends message to mailserver, waiting for delivery if using synchronous
     * mode.
     *
     * @param message
     *            Message previously prepared by prepareMessage()
     * @throws MessagingException
     *             when problems sending the mail arise
     * @throws InterruptedException
     *             when interrupted while waiting for delivery in synchronous
     *             mode
     */
public void execute(Message message) throws MessagingException, InterruptedException {
    Transport tr = null;
    try {
        tr = session.getTransport(getProtocol());
        SynchronousTransportListener listener = null;
        if (synchronousMode) {
            listener = new SynchronousTransportListener();
            tr.addTransportListener(listener);
        }
        if (useAuthentication) {
            tr.connect(smtpServer, username, password);
        } else {
            tr.connect();
        }
        tr.sendMessage(message, message.getAllRecipients());
        if (listener != null) /*synchronousMode==true*/
        {
            // listener cannot be null here
            listener.attend();
        }
    } finally {
        if (tr != null) {
            try {
                tr.close();
            } catch (Exception e) {
            // NOOP
            }
        }
        logger.debug("transport closed");
    }
    logger.debug("message sent");
}
Also used : Transport(javax.mail.Transport) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Aggregations

Transport (javax.mail.Transport)41 Session (javax.mail.Session)28 MimeMessage (javax.mail.internet.MimeMessage)24 JMSession (com.zimbra.cs.util.JMSession)18 MessagingException (javax.mail.MessagingException)18 Test (org.junit.Test)16 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)14 SharedByteArrayInputStream (javax.mail.util.SharedByteArrayInputStream)14 InternetAddress (javax.mail.internet.InternetAddress)11 Properties (java.util.Properties)9 Date (java.util.Date)7 Message (javax.mail.Message)6 NoSuchProviderException (javax.mail.NoSuchProviderException)6 SendFailedException (javax.mail.SendFailedException)6 IOException (java.io.IOException)5 SMTPMessage (com.sun.mail.smtp.SMTPMessage)2 SMTPTransport (com.sun.mail.smtp.SMTPTransport)2 Address (javax.mail.Address)2 Multipart (javax.mail.Multipart)2 AddressException (javax.mail.internet.AddressException)2