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

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

Introduction

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

Prototype

public Email setSubject(final String aSubject) 

Source Link

Document

Set the email subject.

Usage

From source file:de.maklerpoint.office.Marketing.Tools.SendNewsletter.java

/**
 * //from  ww w  .jav  a  2  s. co m
 * @param nl
 * @param sub
 * @throws EmailException
 */

public static void sendNewsletter(NewsletterObj nl, NewsletterSubscriberObj[] sub) throws EmailException {

    for (int i = 0; i < sub.length; i++) {
        HtmlEmail email = new HtmlEmail();
        email.setHostName(Config.get("mailHost", null));

        if (Config.getConfigInt("mailPort", 25) != 25)
            email.setSmtpPort(Config.getConfigInt("mailPort", 25));

        if (Config.getConfigBoolean("mailAuth", true))
            email.setAuthentication(Config.get("mailUser", null), Config.get("mailPassword", null));

        email.setFrom(nl.getSenderMail(), nl.getSender());
        email.setSubject(nl.getSubject());
        email.setHtmlMsg(nl.getText());
        email.setTextMsg("Ihr E-Mail Client untersttzt keine HTML Nachrichten.");

        email.addTo(sub[i].getEmail(), sub[i].getName());
        email.send();
    }
}

From source file:gribbit.util.SendEmail.java

/** Send an email. Don't forget to use fully-qualified URLs in the message body. */
public static void sendEmail(final String toName, final String to, final String subject,
        final DataModel message, final String messagePlainText) {
    // Queue sending of email in a new thread
    GribbitServer.vertx.executeBlocking(future -> {
        if (GribbitProperties.SMTP_SERVER == null || GribbitProperties.SEND_EMAIL_ADDRESS == null
                || GribbitProperties.SEND_EMAIL_PASSWORD == null || GribbitProperties.SEND_EMAIL_ADDRESS == null
                || GribbitProperties.SEND_EMAIL_NAME == null) {
            throw new RuntimeException("SMTP is not fully configured in the properties file");
        }//  w  w w. ja  va 2s .  c  o m

        String fullEmailAddr = "\"" + toName + "\" <" + to + ">";
        try {
            HtmlEmail email = new ImageHtmlEmail();
            email.setDebug(false);

            email.setHostName(GribbitProperties.SMTP_SERVER);
            email.setSmtpPort(GribbitProperties.SMTP_PORT);
            email.setAuthenticator(new DefaultAuthenticator(GribbitProperties.SEND_EMAIL_ADDRESS,
                    GribbitProperties.SEND_EMAIL_PASSWORD));
            email.setStartTLSRequired(true);

            email.addTo(to, toName);
            email.setFrom(GribbitProperties.SEND_EMAIL_ADDRESS, GribbitProperties.SEND_EMAIL_NAME);
            email.setSubject(subject);
            email.setHtmlMsg(message.toString());
            email.setTextMsg(messagePlainText);

            email.send();

            Log.info("Sent email to " + fullEmailAddr + " : " + subject);

        } catch (EmailException e) {
            Log.exception("Failure while trying to send email to " + fullEmailAddr + " : " + subject, e);
        }
        future.complete();

    }, res -> {
        if (res.failed()) {
            Log.error("Exception while trying to send email");
        }
    });
}

From source file:com.baifendian.swordfish.common.mail.MailSendUtil.java

/**
 * ??/*from   w  w  w  . j ava2  s .  com*/
 *
 * @param receivers
 * @param title
 * @param content
 * @return
 */
public static boolean sendMails(Collection<String> receivers, String title, String content) {
    if (receivers == null) {
        LOGGER.error("Mail receivers is null.");
        return false;
    }

    receivers.removeIf((from) -> (StringUtils.isEmpty(from)));

    if (receivers.isEmpty()) {
        LOGGER.error("Mail receivers is empty.");
        return false;
    }

    // ?? email
    HtmlEmail email = new HtmlEmail();

    try {
        //  SMTP ?????, 163 "smtp.163.com"
        email.setHostName(mailServerHost);

        email.setSmtpPort(mailServerPort);

        // ?
        email.setCharset("UTF-8");
        // 
        for (String receiver : receivers) {
            email.addTo(receiver);
        }
        // ??
        email.setFrom(mailSender, mailSender);
        // ???????-??????
        email.setAuthentication(mailSender, mailPasswd);
        // ???
        email.setSubject(title);
        // ???? HtmlEmail? HTML 
        email.setMsg(content);
        // ??
        email.send();

        return true;
    } catch (Throwable e) {
        LOGGER.error("Send email to {} failed", StringUtils.join(",", receivers), e);
    }

    return false;
}

From source file:mailbox.EmailHandler.java

private static void reply(IMAPMessage origin, String username, String emailAddress, String msg) {
    final HtmlEmail email = new HtmlEmail();

    try {//w w  w.j a  v a2  s  .com
        email.setFrom(Config.getEmailFromSmtp(), Config.getSiteName());
        email.addTo(emailAddress, username);
        String subject;
        if (!origin.getSubject().toLowerCase().startsWith("re:")) {
            subject = "Re: " + origin.getSubject();
        } else {
            subject = origin.getSubject();
        }
        email.setSubject(subject);
        email.setTextMsg(msg);
        email.setCharset("utf-8");
        email.setSentDate(new Date());
        email.addHeader("In-Reply-To", origin.getMessageID());
        email.addHeader("References", origin.getMessageID());
        Mailer.send(email);
        String escapedTitle = email.getSubject().replace("\"", "\\\"");
        String logEntry = String.format("\"%s\" %s", escapedTitle, email.getToAddresses());
        play.Logger.of("mail").info(logEntry);
    } catch (Exception e) {
        Logger.warn("Failed to send an email: " + email + "\n" + ExceptionUtils.getStackTrace(e));
    }
}

From source file:it.vige.greenarea.test.mail.SendMailTest.java

@Test
public void testSendMailToGoogle() throws Exception {
    HtmlEmail email = new HtmlEmail();
    try {/*from  w  w  w  .j av  a2 s .  c o  m*/
        email.setSubject("prova");
        email.setHtmlMsg("<div>ciao</div>");
        email.addTo("luca.stancapiano@vige.it");
        email.setSmtpPort(587);
        email.setHostName("smtp.gmail.com");
        email.setFrom("greenareavige@gmail.com");
        email.setAuthentication("greenareavige@gmail.com", "vulitgreenarea");
        email.setTLS(true);
        email.send();
    } catch (EmailException e) {
        fail();
    }

}

From source file:com.github.robozonky.notifications.EmailHandler.java

@Override
public void send(final SessionInfo sessionInfo, final String subject, final String message,
        final String fallbackMessage) throws Exception {
    final HtmlEmail email = createNewEmail(sessionInfo);
    email.setSubject(subject);
    email.setHtmlMsg(message);/*from   ww w .  j a  v a  2s  .c om*/
    email.setTextMsg(fallbackMessage);
    LOGGER.debug("Will send '{}' from {} to {} through {}:{} as {}.", email.getSubject(),
            email.getFromAddress(), email.getToAddresses(), email.getHostName(), email.getSmtpPort(),
            getSmtpUsername());
    email.send();
}

From source file:io.mif.labanorodraugai.services.EmailService.java

public void SendInvitationEmail(Account sender, String toEmail) throws EmailException, MalformedURLException {
    //ImageHtmlEmail email = new ImageHtmlEmail();
    HtmlEmail email = new HtmlEmail();
    setUpHtmlEmail(email);// w  w w  .j  a  v  a  2  s .  c o  m
    email.addTo(toEmail);
    email.setSubject("Labanoro draug kvietimas");

    StringBuilder msg = new StringBuilder();
    //msg.append("<div><img src=\"" + baseUrl + "/images/lab  anorodraugai.JPG\"></div>");
    msg.append("<h4>Sveiki,</h4>");
    msg.append("<p>" + sender.getName() + " " + sender.getLastname()
            + " kvie?ia Jus tapti bendrijos Labanoro draugai nariu!</p>");
    msg.append("<p>T padaryti galite usiregistrav ");
    msg.append("<a href=" + "\"http://localhost:8080/LabanoroDraugai/registration/registration.html\">");
    msg.append("?ia</a></p>");

    email.setContent(msg.toString(), EmailConstants.TEXT_HTML);

    email.send();
}

From source file:io.mif.labanorodraugai.services.EmailService.java

public void sendApprovalRequestEmail(AccountApproval approval) throws EmailException, MalformedURLException {
    HtmlEmail email = new HtmlEmail();
    setUpHtmlEmail(email);//from w w w. ja v  a2  s  .  c  om
    email.addTo(approval.getApprover().getEmail());
    email.setSubject("Naujo nario rekomendacija");

    Account candidate = approval.getCandidate();

    StringBuilder msg = new StringBuilder();
    //msg.append("<div><img src=\"" + baseUrl + "/images/lab  anorodraugai.JPG\"></div>");
    msg.append("<h4>Sveiki,</h4>");
    msg.append("<p>" + candidate.getName() + " " + candidate.getLastname() + " (" + candidate.getEmail()
            + ") nori tapti Labanoro Draugai nariu ir prao Js suteikti rekomendacij!</p>");
    msg.append("<p>T padaryti galite: ");
    msg.append("<a href=" + "\"http://localhost:8080/LabanoroDraugai/registration/approval.html?gen="
            + approval.getGeneratedId() + "\">");
    msg.append("?ia</a></p>");

    email.setContent(msg.toString(), EmailConstants.TEXT_HTML);

    email.send();
}

From source file:io.marto.aem.utils.email.FreemarkerTemplatedMailer.java

private HtmlEmail constructEmail(final String[] recipients, String sender, final String subject,
        String template, Object model) throws EmailException {
    final HtmlEmail email = new HtmlEmail();

    email.setMsg(renderBody(template, model));
    if (subject != null) {
        email.setSubject(subject);
    }//  w w w . j  av a  2 s . c o m
    if (sender != null) {
        email.setFrom(sender);
    }

    for (String recipient : recipients) {
        email.addTo(recipient);
    }

    return email;
}

From source file:com.qatickets.service.MailService.java

public void send(EmailMessage msg) throws Exception {

    HtmlEmail email = new HtmlEmail();

    email.setSmtpPort(port);/*from   w ww  .  j  av  a  2 s .  c om*/
    email.setHostName(host);

    email.setHtmlMsg(msg.getHTMLContent());
    email.setTextMsg(msg.getTextContent());
    email.setSubject(msg.getSubject());

    email.addTo(msg.getRecepient().getEmail(), msg.getRecepient().getName());
    //      email.setFrom(systemOwner, "QATickets.com");

    email.send();

}