Example usage for javax.mail Transport getURLName

List of usage examples for javax.mail Transport getURLName

Introduction

In this page you can find the example usage for javax.mail Transport getURLName.

Prototype

public URLName getURLName() 

Source Link

Document

Return a URLName representing this service.

Usage

From source file:nl.nn.adapterframework.senders.MailSender.java

protected void putOnTransport(Message msg) throws SenderException {
    // connect to the transport 
    Transport transport = null;
    try {/*from  w  w  w  .j a  v  a  2  s .com*/
        CredentialFactory cf = new CredentialFactory(getSmtpAuthAlias(), getSmtpUserid(), getSmtpPassword());
        transport = session.getTransport("smtp");
        transport.connect(getSmtpHost(), cf.getUsername(), cf.getPassword());
        if (log.isDebugEnabled()) {
            log.debug("MailSender [" + getName() + "] connected transport to URL [" + transport.getURLName()
                    + "]");
        }
        transport.sendMessage(msg, msg.getAllRecipients());
        transport.close();
    } catch (Exception e) {
        throw new SenderException("MailSender [" + getName() + "] cannot connect send message to smtpHost ["
                + getSmtpHost() + "]", e);
    } finally {
        if (transport != null) {
            try {
                transport.close();
            } catch (MessagingException e1) {
                log.warn("MailSender [" + getName() + "] got exception closing connection", e1);
            }
        }
    }
}