Search in sources :

Example 11 with HtmlEmail

use of org.apache.commons.mail.HtmlEmail in project shepher by XiaoMi.

the class GeneralMailSender method send.

protected void send(String mailAddress, String title, String content) {
    if (StringUtils.isBlank(mailAddress)) {
        return;
    }
    try {
        Email email = new HtmlEmail();
        email.setHostName(hostname);
        email.setAuthenticator(new DefaultAuthenticator(username, password));
        email.setSmtpPort(port);
        email.setFrom(from, fromname);
        email.setSubject(title);
        email.setMsg(content);
        email.addTo(mailAddress.split(mailAddressEndSeparator));
        email.send();
    } catch (Exception e) {
        logger.error("Send Mail Error", e);
    }
}
Also used : Email(org.apache.commons.mail.Email) HtmlEmail(org.apache.commons.mail.HtmlEmail) HtmlEmail(org.apache.commons.mail.HtmlEmail) DefaultAuthenticator(org.apache.commons.mail.DefaultAuthenticator)

Example 12 with HtmlEmail

use of org.apache.commons.mail.HtmlEmail in project structr by structr.

the class MailHelper method _sendHtmlMail.

private static String _sendHtmlMail(final String from, final String fromName, final String to, final String toName, final String cc, final String bcc, final String bounce, final String subject, final String htmlContent, final String textContent, final List<DynamicMailAttachment> attachments) throws EmailException {
    if (Settings.SmtpTesting.getValue()) {
        return "Testing";
    }
    HtmlEmail mail = new HtmlEmail();
    setup(mail, to, toName, from, fromName, cc, bcc, bounce, subject);
    mail.setHtmlMsg(htmlContent);
    mail.setTextMsg(textContent);
    if (attachments != null) {
        for (final DynamicMailAttachment attachment : attachments) {
            if (attachment.isDynamic()) {
                mail.attach(attachment.getDataSource(), attachment.getName(), attachment.getDescription(), attachment.getDisposition());
            } else {
                mail.attach(attachment);
            }
        }
    }
    return mail.send();
}
Also used : HtmlEmail(org.apache.commons.mail.HtmlEmail)

Example 13 with HtmlEmail

use of org.apache.commons.mail.HtmlEmail in project graylog2-server by Graylog2.

the class EmailSender method createEmailWithBody.

Email createEmailWithBody(EmailEventNotificationConfig config, Map<String, Object> model) throws EmailException {
    if (!isNullOrEmpty(config.htmlBodyTemplate())) {
        HtmlEmail email = emailFactory.htmlEmail();
        email.setTextMsg(buildBody(config, model));
        email.setHtmlMsg(buildHtmlBody(config, model));
        return email;
    } else {
        SimpleEmail email = emailFactory.simpleEmail();
        email.setMsg(buildBody(config, model));
        return email;
    }
}
Also used : HtmlEmail(org.apache.commons.mail.HtmlEmail) SimpleEmail(org.apache.commons.mail.SimpleEmail)

Example 14 with HtmlEmail

use of org.apache.commons.mail.HtmlEmail in project ninja by ninjaframework.

the class CommonsMailHelperImplTest method testCreateMultiPartEmailWithContent.

@Test
public void testCreateMultiPartEmailWithContent() throws Exception {
    // /////////////////////////////////////////////////////////////////////
    // Test with text only content
    // /////////////////////////////////////////////////////////////////////
    Mail mail = new MailImpl();
    // set only text:
    mail.setBodyText("simple body text");
    MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);
    assertTrue(multiPartEmail instanceof MultiPartEmail);
    // /////////////////////////////////////////////////////////////////////
    // Test with html only content
    // /////////////////////////////////////////////////////////////////////
    mail = new MailImpl();
    // set only text:
    mail.setBodyHtml("<br>simple body text<br>");
    multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);
    assertTrue(multiPartEmail instanceof HtmlEmail);
    // /////////////////////////////////////////////////////////////////////
    // Test with html AND text content
    // /////////////////////////////////////////////////////////////////////
    mail = new MailImpl();
    // set only text:
    mail.setBodyText("simple body text");
    mail.setBodyHtml("<br>simple body text<br>");
    multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);
    assertTrue(multiPartEmail instanceof HtmlEmail);
}
Also used : Mail(ninja.postoffice.Mail) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) HtmlEmail(org.apache.commons.mail.HtmlEmail) MailImpl(ninja.postoffice.common.MailImpl) Test(org.junit.Test)

Example 15 with HtmlEmail

use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.

the class SendMailSsl method initializeMail.

/**
 * Creates a {@link HtmlEmail} object configured as per the AuthMe config
 * with the given email address as recipient.
 *
 * @param emailAddress the email address the email is destined for
 * @return the created HtmlEmail object
 * @throws EmailException if the mail is invalid
 */
public HtmlEmail initializeMail(String emailAddress) throws EmailException {
    String senderMail = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_ADDRESS)) ? settings.getProperty(EmailSettings.MAIL_ACCOUNT) : settings.getProperty(EmailSettings.MAIL_ADDRESS);
    String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)) ? senderMail : settings.getProperty(EmailSettings.MAIL_SENDER_NAME);
    String mailPassword = settings.getProperty(EmailSettings.MAIL_PASSWORD);
    int port = settings.getProperty(EmailSettings.SMTP_PORT);
    HtmlEmail email = new HtmlEmail();
    email.setCharset(EmailConstants.UTF_8);
    email.setSmtpPort(port);
    email.setHostName(settings.getProperty(EmailSettings.SMTP_HOST));
    email.addTo(emailAddress);
    email.setFrom(senderMail, senderName);
    email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
    email.setAuthentication(settings.getProperty(EmailSettings.MAIL_ACCOUNT), mailPassword);
    if (settings.getProperty(PluginSettings.LOG_LEVEL).includes(LogLevel.DEBUG)) {
        email.setDebug(true);
    }
    setPropertiesForPort(email, port);
    return email;
}
Also used : HtmlEmail(org.apache.commons.mail.HtmlEmail)

Aggregations

HtmlEmail (org.apache.commons.mail.HtmlEmail)47 EmailException (org.apache.commons.mail.EmailException)24 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 Email (org.apache.commons.mail.Email)7 MultiPartEmail (org.apache.commons.mail.MultiPartEmail)6 IOException (java.io.IOException)5 InternetAddress (javax.mail.internet.InternetAddress)5 DefaultAuthenticator (org.apache.commons.mail.DefaultAuthenticator)5 Configuration (freemarker.template.Configuration)4 Template (freemarker.template.Template)4 File (java.io.File)4 List (java.util.List)4 Map (java.util.Map)4 EmailAttachment (org.apache.commons.mail.EmailAttachment)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 JobExecutionException (org.quartz.JobExecutionException)4 RenderResult (cn.bran.japid.template.RenderResult)3 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)3