Example usage for org.apache.commons.mail Email setSubject

List of usage examples for org.apache.commons.mail Email setSubject

Introduction

In this page you can find the example usage for org.apache.commons.mail Email setSubject.

Prototype

public Email setSubject(final String aSubject) 

Source Link

Document

Set the email subject.

Usage

From source file:com.kylinolap.common.util.MailService.java

/**
 * //from  w w w .  j  a v  a2  s. c  om
 * @param receivers
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content) throws IOException {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        ((HtmlEmail) email).setHtmlMsg(content);
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}

From source file:com.ning.billing.util.email.DefaultEmailSender.java

private void sendEmail(final List<String> to, final List<String> cc, final String subject, final Email email)
        throws EmailApiException {
    try {/* ww w.j a  v  a  2s . co  m*/
        email.setSmtpPort(config.getSmtpPort());
        if (config.useSmtpAuth()) {
            email.setAuthentication(config.getSmtpUserName(), config.getSmtpPassword());
        }
        email.setHostName(config.getSmtpServerName());
        email.setFrom(config.getDefaultFrom());

        email.setSubject(subject);

        if (to != null) {
            for (final String recipient : to) {
                email.addTo(recipient);
            }
        }

        if (cc != null) {
            for (final String recipient : cc) {
                email.addCc(recipient);
            }
        }

        email.setSSL(config.useSSL());

        log.info("Sending email to {}, cc {}, subject {}", new Object[] { to, cc, subject });
        email.send();
    } catch (EmailException ee) {
        throw new EmailApiException(ee, ErrorCode.EMAIL_SENDING_FAILED);
    }
}

From source file:com.turn.sorcerer.util.email.Emailer.java

private void sendEmail() throws EmailException, UnknownHostException {

    List<String> addresses = Lists
            .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(ADMIN_EMAIL.getAdmins()));
    logger.info("Sending email to {}", addresses.toString());

    Email email = new HtmlEmail();
    email.setHostName(ADMIN_EMAIL.getHost());
    email.setSocketTimeout(30000); // 30 seconds
    email.setSocketConnectionTimeout(30000); // 30 seconds
    for (String address : addresses) {
        email.addTo(address);//from w ww .j a v a2 s  .  com
    }
    email.setFrom(
            SorcererInjector.get().getModule().getName() + "@" + InetAddress.getLocalHost().getHostName());
    email.setSubject(title);
    email.setMsg(body);
    email.send();

}

From source file:com.esofthead.mycollab.servlet.EmailValidationServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String smtpUserName = request.getParameter("smtpUserName");
    String smtpPassword = request.getParameter("smtpPassword");
    String smtpHost = request.getParameter("smtpHost");
    String smtpPort = request.getParameter("smtpPort");
    String tls = request.getParameter("tls");

    int mailServerPort;
    try {//from   w w  w . j  a v  a2 s.c o  m
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        PrintWriter out = response.getWriter();
        out.write("Port must be an integer value");
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if (tls.equals("true")) {
            email.setSSLOnConnect(true);
        } else {
            email.setSSLOnConnect(false);
        }
        email.setFrom(smtpUserName);
        email.setSubject("MyCollab Test Email");
        email.setMsg("This is a test mail ... :-)");
        email.addTo(smtpUserName);
        email.send();
    } catch (EmailException e) {
        PrintWriter out = response.getWriter();
        out.write("Cannot establish SMTP connection. Please recheck your config.");
        return;
    }
}

From source file:com.patrolpro.beans.SignupClientBean.java

public String sendEmail() {
    try {//from   w  w  w  .j  ava  2s.c om
        boolean isValid = validateInformation();

        if (isValid) {
            StringBuilder emailMessage = new StringBuilder();
            emailMessage.append("Contact Name: " + this.contactName + "\r\n");
            emailMessage.append("Contact Email: " + this.contactEmail + "\r\n");
            emailMessage.append("Contact Phone: " + this.contactPhone + "\r\n");
            emailMessage.append("Company Name: " + this.companyName + "\r\n");
            emailMessage.append(message);

            Email htmlEmail = new SimpleEmail();
            if (message == null || message.length() == 0) {
                message = "No message was provided by the user.";
            }
            htmlEmail.setFrom("signup@patrolpro.com");
            htmlEmail.setSubject("Trial Account Email!");
            htmlEmail.addTo("rharris@ainteractivesolution.com");
            htmlEmail.addTo("ijuneau@ainteractivesolution.com");
            htmlEmail.addCc("jc@champ.net");
            //htmlEmail.setHtmlMsg(emailMessage.toString());
            htmlEmail.setMsg(emailMessage.toString());
            //htmlEmail.setTextMsg(emailMessage.toString());

            htmlEmail.setDebug(true);
            htmlEmail.setAuthenticator(new MailAuthenticator("schedfox", "Sch3dF0x4m3"));
            htmlEmail.setHostName("mail2.champ.net");
            htmlEmail.setSmtpPort(587);
            htmlEmail.send();
            return "sentEmail";
        }
    } catch (Exception exe) {

    }
    return "invalid";
}

From source file:edu.corgi.uco.sendEmails.java

public void sendConfirmation(String email2, String firstName, String lastName, int token, int id)
        throws EmailException {

    Email email = new SimpleEmail();

    email.setDebug(true);/* w ww . j ava 2  s.com*/
    email.setHostName("smtp.gmail.com");
    email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung"));
    email.setStartTLSEnabled(true);
    email.setSmtpPort(587);
    email.setFrom("ucocorgi@gmail.com", "UCO CS Corgi");
    email.setSubject("Account Confirmation");
    email.setMsg(firstName + " " + lastName
            + " please go to the following address http://localhost:8080/Corgi/faces/accountAuth.xhtml "
            + "and enter the token:" + token + " and the ID:" + id + " to confirm and activate your account");
    System.out.print("Email Address: " + email2);
    email.addTo(email2);

    email.send();

}

From source file:com.cqecom.cms.components.eMailer.TrialOsubEmailController.java

public void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {
    try {//www.  j a  v  a 2 s.  com
        String strLicenseName = "";
        String strLicensePassword = "";
        String strLanguageName = "";
        String strEndsAt = "";
        String strLanguageSlug = "";
        String strTrialUrl = "";
        String strOfferPromo = "";
        String strEmailTemplateUrl = "";
        String strFollowupEmailTemplateUrl = "";
        String strEmailSubject = "";
        String strEmailFrom = "";
        String followupEmail = "";
        String strFollowupEmailSubject = "";

        if (request != null) {
            strLicenseName = getParamValue(request, "license_name");
            strLicensePassword = getParamValue(request, "license_password");
            strLanguageName = getParamValue(request, "language_name");
            strEndsAt = getParamValue(request, "ends_at");
            strLanguageSlug = getParamValue(request, "language_slug");
            strTrialUrl = getParamValue(request, "trial_url");
            strOfferPromo = getParamValue(request, "offer_promo");
            strEmailTemplateUrl = getParamValue(request, "email_template_url");
            strFollowupEmailTemplateUrl = getParamValue(request, "followup_email_template_url");
            strEmailSubject = getParamValue(request, "email_subject");
            strFollowupEmailSubject = getParamValue(request, "followup_email_subject");
            strEmailFrom = getParamValue(request, "email_from");
            followupEmail = getParamValue(request, "followup_email");
        }

        if (followupEmail.equals("true")) {
            strEmailTemplateUrl = strFollowupEmailTemplateUrl;
            strEmailSubject = strFollowupEmailSubject;
        }

        session = repository.loginAdministrative(null);
        String pageHtml = session.getRootNode().getNode(strEmailTemplateUrl + "/jcr:content/content")
                .getProperty("text").getValue().getString();

        pageHtml = replaceToken(pageHtml, "license_name", strLicenseName);
        pageHtml = replaceToken(pageHtml, "license_password", strLicensePassword);
        pageHtml = replaceToken(pageHtml, "language_name", strLanguageName);
        pageHtml = replaceToken(pageHtml, "ends_at", strEndsAt);
        pageHtml = replaceToken(pageHtml, "language_slug", strLanguageSlug);
        pageHtml = replaceToken(pageHtml, "trial_url", strTrialUrl);
        pageHtml = replaceToken(pageHtml, "offer_promo", strOfferPromo);
        Email emailObj = new HtmlEmail();
        emailObj.setContent(pageHtml.toString(), "text/html");

        if (!strEmailFrom.equals(""))
            emailObj.setFrom(strEmailFrom, "CqEcom " + strLanguageName + " Trial");

        if (!strLicenseName.equals(""))
            emailObj.addTo(strLicenseName);

        if (!strEmailSubject.equals(""))
            emailObj.setSubject(strEmailSubject);
        ms.sendEmail(emailObj);
        logger.info("Mail sent to => " + strLicenseName);
    } catch (Exception ex) {
        logger.info(ex.getMessage());
    } finally {
        if (session != null)
            session.logout();
    }
}

From source file:com.basetechnology.s0.agentserver.mail.AgentMail.java

public int sendMessage(User user, String toEmail, String toName, String subject, String message,
        String messageTrailer1, String messageTrailer2) throws AgentServerException {
    try {/*from w ww  .j av a  2 s.com*/
        // Wait until we have mail access
        agentServer.mailAccessManager.wait(user, toEmail);

        int messageId = ++nextMessageId;
        log.info("Sending mail on behalf of user " + user.id + " with message Id " + messageId + " To: '<"
                + toName + ">" + toEmail + "' Subject: '" + subject + "'");

        Email email = new SimpleEmail();
        email.setDebug(debug);
        email.setHostName(mailServerHostName);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(mailServerUserName, mailServerUserPassword));
        email.setTLS(true);
        email.setFrom(mailServerFromEmail, mailServerFromName);
        // TODO: Reconsider whether we want to always mess with subject line
        email.setSubject(subject + " (#" + messageId + ")");
        email.setMsg(message + messageTrailer1 + (messageTrailer2 != null ? messageId + messageTrailer2 : ""));
        email.addTo(toEmail, toName);
        email.send();
        log.info("Message sent");

        // Return the message Id
        return messageId;
    } catch (EmailException e) {
        e.printStackTrace();
        throw new AgentServerException("EmailException sending email - " + e.getMessage());
    }
}

From source file:com.mirth.connect.connectors.smtp.SmtpSenderService.java

@Override
public Object invoke(String channelId, String method, Object object, String sessionId) throws Exception {
    if (method.equals("sendTestEmail")) {
        SmtpDispatcherProperties props = (SmtpDispatcherProperties) object;

        String host = replacer.replaceValues(props.getSmtpHost(), channelId);
        String portString = replacer.replaceValues(props.getSmtpPort(), channelId);

        int port = -1;
        try {/* w  ww. ja v  a  2  s  . co  m*/
            port = Integer.parseInt(portString);
        } catch (NumberFormatException e) {
            return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE,
                    "Invalid port: \"" + portString + "\"");
        }

        String secure = props.getEncryption();

        boolean authentication = props.isAuthentication();

        String username = replacer.replaceValues(props.getUsername(), channelId);
        String password = replacer.replaceValues(props.getPassword(), channelId);
        String to = replacer.replaceValues(props.getTo(), channelId);
        String from = replacer.replaceValues(props.getFrom(), channelId);

        Email email = new SimpleEmail();
        email.setDebug(true);
        email.setHostName(host);
        email.setSmtpPort(port);

        if ("SSL".equalsIgnoreCase(secure)) {
            email.setSSL(true);
        } else if ("TLS".equalsIgnoreCase(secure)) {
            email.setTLS(true);
        }

        if (authentication) {
            email.setAuthentication(username, password);
        }

        email.setSubject("Mirth Connect Test Email");

        try {
            for (String toAddress : StringUtils.split(to, ",")) {
                email.addTo(toAddress);
            }

            email.setFrom(from);
            email.setMsg(
                    "Receipt of this email confirms that mail originating from this Mirth Connect Server is capable of reaching its intended destination.\n\nSMTP Configuration:\n- Host: "
                            + host + "\n- Port: " + port);

            email.send();
            return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS,
                    "Sucessfully sent test email to: " + to);
        } catch (EmailException e) {
            return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, e.getMessage());
        }
    }

    return null;
}

From source file:com.swissbit.ifttt.IFTTTConfgurationImpl.java

/** {@inheritDoc} */
@Override/*from w ww  .ja  va 2s  .com*/
public void trigger() {
    LOGGER.debug("IFTTT Email is getting sent...");

    final List<String> tags = this.retrieveHashtags(this.m_hashTags);

    if (tags.size() == 0) {
        return;
    }

    if (tags.size() > 0) {
        for (final String tag : tags) {
            try {
                final Email email = new SimpleEmail();
                email.setHostName(this.m_smtpHost);
                email.setSmtpPort(this.m_smtpPort);
                email.setAuthenticator(new DefaultAuthenticator(this.m_smtpUsername, this.m_smtpPassword));
                email.setSSL(true);
                email.setFrom(this.m_smtpUsername);
                email.setSubject(tag);
                email.setMsg("This is a test mail ... :-)");
                email.addTo(TRIGGER_EMAIL);
                email.send();
            } catch (final EmailException e) {
                LOGGER.error(Throwables.getStackTraceAsString(e));
            }
        }
    }
    LOGGER.debug("IFTTT Email is sent...Done");
}