Example usage for org.apache.commons.mail MultiPartEmail addReplyTo

List of usage examples for org.apache.commons.mail MultiPartEmail addReplyTo

Introduction

In this page you can find the example usage for org.apache.commons.mail MultiPartEmail addReplyTo.

Prototype

public Email addReplyTo(final String email) throws EmailException 

Source Link

Document

Add a reply to address to the email.

Usage

From source file:com.maxl.java.amikodesk.Emailer.java

public void send() {
    try {//w  w w .  j a  v  a 2s.  c  o m
        MultiPartEmail email = new MultiPartEmail();
        email.setHostName(m_es);
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator(m_el, m_ep));
        email.setSSLOnConnect(true);

        // Create email message
        email.setSubject(m_subject); // Subject         
        email.setMsg(m_body); // Body
        email.setFrom(m_from); // From field      
        email.addTo(m_recipient); // Recipient   
        if (m_singlecc != null && !m_singlecc.isEmpty())
            email.addCc(m_singlecc); // CC
        if (m_replyTo != null && !m_replyTo.isEmpty())
            email.addReplyTo(m_replyTo); // Reply-To
        // Add attachments
        for (Map.Entry<String, String> entry : m_map_of_attachments.entrySet()) {
            EmailAttachment attachment = new EmailAttachment();
            attachment.setName(entry.getKey());
            attachment.setPath(entry.getValue());
            attachment.setDisposition(EmailAttachment.ATTACHMENT);
            email.attach(attachment);
        }

        // Send email
        email.send();

        // Clear map
        m_map_of_attachments.clear();
    } catch (EmailException e) {
        e.printStackTrace();
    }
}

From source file:org.agnitas.util.AgnUtils.java

/**
 * Sends the attachment of an email.//from   ww w  .  j a  v a  2s .  com
 */
public static boolean sendEmailAttachment(String from, String to_adrList, String cc_adrList, String subject,
        String txt, byte[] att_data, String att_name, String att_type) {
    boolean result = true;

    try {
        // Create the email message
        MultiPartEmail email = new MultiPartEmail();
        email.setCharset("UTF-8");
        email.setHostName(getSmtpMailRelayHostname());
        email.setFrom(from);
        email.setSubject(subject);
        email.setMsg(txt);

        // bounces and reply forwarded to assistance@agnitas.de
        email.addReplyTo("assistance@agnitas.de");
        email.setBounceAddress("assistance@agnitas.de");

        // Set to-recipient email addresses
        InternetAddress[] toAddresses = getEmailAddressesFromList(to_adrList);
        if (toAddresses != null && toAddresses.length > 0) {
            for (InternetAddress singleAdr : toAddresses) {
                email.addTo(singleAdr.getAddress());
            }
        }

        // Set cc-recipient email addresses
        InternetAddress[] ccAddresses = getEmailAddressesFromList(cc_adrList);
        if (ccAddresses != null && ccAddresses.length > 0) {
            for (InternetAddress singleAdr : ccAddresses) {
                email.addCc(singleAdr.getAddress());
            }
        }

        // Create and add the attachment
        ByteArrayDataSource attachment = new ByteArrayDataSource(att_data, att_type);
        email.attach(attachment, att_name, "EMM-Report");

        // send the email
        email.send();
    } catch (Exception e) {
        logger.error("sendEmailAttachment: " + e.getMessage(), e);
        result = false;
    }

    return result;
}

From source file:org.agnitas.util.ImportUtils.java

public static boolean sendEmailWithAttachments(String from, String fromName, String to, String subject,
        String message, EmailAttachment[] attachments) {
    boolean result = true;
    try {/*from ww w .j  av  a 2s  . com*/
        // Create the email message
        MultiPartEmail email = new MultiPartEmail();
        email.setCharset("UTF-8");
        email.setHostName(AgnUtils.getDefaultValue("system.mail.host"));
        email.addTo(to);

        if (fromName == null || fromName.equals(""))
            email.setFrom(from);
        else
            email.setFrom(from, fromName);

        email.setSubject(subject);
        email.setMsg(message);

        //bounces and reply forwarded to support@agnitas.de
        String replyName = AgnUtils.getDefaultValue("import.report.replyTo.name");
        if (replyName == null || replyName.equals(""))
            email.addReplyTo(AgnUtils.getDefaultValue("import.report.replyTo.address"));
        else
            email.addReplyTo(AgnUtils.getDefaultValue("import.report.replyTo.address"), replyName);

        email.setBounceAddress(AgnUtils.getDefaultValue("import.report.bounce"));

        // Create and attach attachments
        for (EmailAttachment attachment : attachments) {
            ByteArrayDataSource dataSource = new ByteArrayDataSource(attachment.getData(),
                    attachment.getType());
            email.attach(dataSource, attachment.getName(), attachment.getDescription());
        }

        // send the email
        email.send();
    } catch (Exception e) {
        AgnUtils.logger().error("sendEmailAttachment: " + e.getMessage());
        result = false;
    }
    return result;
}