use of org.apache.commons.mail.HtmlEmail in project cerberus-source by cerberustesting.
the class EmailService method sendHtmlMail.
@Override
public void sendHtmlMail(Email cerberusEmail) throws Exception {
HtmlEmail email = new HtmlEmail();
email.setSmtpPort(cerberusEmail.getSmtpPort());
email.setHostName(cerberusEmail.getHost());
email.setFrom(cerberusEmail.getFrom());
email.setSubject(cerberusEmail.getSubject());
email.setHtmlMsg(cerberusEmail.getBody());
if (cerberusEmail.isSetTls()) {
email = (HtmlEmail) email.setStartTLSEnabled(true);
}
// email.setTLS(cerberusEmail.isSetTls());
email.setDebug(true);
if (!StringUtils.isNullOrEmpty(cerberusEmail.getUserName()) || !StringUtils.isNullOrEmpty(cerberusEmail.getPassword())) {
email.setAuthentication(cerberusEmail.getUserName(), cerberusEmail.getPassword());
}
String[] destinataire = cerberusEmail.getTo().split(";");
for (int i = 0; i < destinataire.length; i++) {
String name;
String emailaddress;
if (destinataire[i].contains("<")) {
String[] destinatairedata = destinataire[i].split("<");
name = destinatairedata[0].trim();
emailaddress = destinatairedata[1].replace(">", "").trim();
} else {
name = "";
emailaddress = destinataire[i];
}
email.addTo(emailaddress, name);
}
if (!StringUtil.isNullOrEmpty(cerberusEmail.getCc())) {
String[] copy = cerberusEmail.getCc().split(";");
for (int i = 0; i < copy.length; i++) {
String namecc;
String emailaddresscc;
if (copy[i].contains("<")) {
String[] copydata = copy[i].split("<");
namecc = copydata[0].trim();
emailaddresscc = copydata[1].replace(">", "").trim();
} else {
namecc = "";
emailaddresscc = copy[i];
}
email.addCc(emailaddresscc, namecc);
}
}
email.send();
}
use of org.apache.commons.mail.HtmlEmail in project acs-aem-commons by Adobe-Consulting-Services.
the class EmailServiceImpl method sendEmail.
@Override
public List<InternetAddress> sendEmail(String templatePath, Map<String, String> emailParams, Map<String, DataSource> attachments, InternetAddress... recipients) {
List<InternetAddress> failureList = new ArrayList<InternetAddress>();
if (recipients == null || recipients.length <= 0) {
throw new IllegalArgumentException(MSG_INVALID_RECIPIENTS);
}
final MailTemplate mailTemplate = this.getMailTemplate(templatePath);
final Class<? extends Email> mailType;
if (attachments != null && attachments.size() > 0) {
mailType = HtmlEmail.class;
} else {
mailType = this.getMailType(templatePath);
}
final MessageGateway<Email> messageGateway = messageGatewayService.getGateway(mailType);
for (final InternetAddress address : recipients) {
try {
// Get a new email per recipient to avoid duplicate attachments
Email email = getEmail(mailTemplate, mailType, emailParams);
email.setTo(Collections.singleton(address));
if (attachments != null && attachments.size() > 0) {
for (Map.Entry<String, DataSource> entry : attachments.entrySet()) {
((HtmlEmail) email).attach(entry.getValue(), entry.getKey(), null);
}
}
messageGateway.send(email);
} catch (Exception e) {
failureList.add(address);
log.error("Error sending email to [ " + address + " ]", e);
}
}
return failureList;
}
use of org.apache.commons.mail.HtmlEmail in project dubidubi by lzzzz4.
the class MailUtils method sendMail.
public static boolean sendMail(MailDTO dto) {
boolean isSucess = false;
Email email = new HtmlEmail();
email.setHostName("smtp.qq.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("1622472966@qq.com", "lyvihlbjmafcbdab"));
email.setSSLOnConnect(true);
try {
// 发件人
email.setFrom("1622472966@qq.com");
// 邮箱头
email.setSubject(dto.getTitle());
// 邮箱身体
email.setContent("<h2>hhhh公司的验证码</h2><br><p><strong>验证码为" + dto.getContent() + "</strong></p><br>谢谢您的姿瓷", "text/html;charset=utf-8");
// email.setContent("<img
// src='http://img.99mm.net/small/2017/2389.jpg'></img>",
// "text/html;charset=utf-8");
email.addTo(dto.getMail());
email.send();
isSucess = true;
} catch (EmailException e) {
e.printStackTrace();
}
return isSucess;
}
use of org.apache.commons.mail.HtmlEmail in project ngtesting-platform by aaronchen2k.
the class MailServiceImpl method sendTemplateMail.
@Override
public void sendTemplateMail(String subject, String templateName, String toEmail, Map<String, String> map) {
Template template = null;
Configuration freeMarkerConfig = null;
HtmlEmail mail = new HtmlEmail();
try {
String dir = getFilePath();
freeMarkerConfig = new Configuration();
freeMarkerConfig.setDirectoryForTemplateLoading(new File(dir));
String file = getFileName(templateName);
template = freeMarkerConfig.getTemplate(file, new Locale("Zh_cn"), "UTF-8");
String htmlText = FreeMarkerTemplateUtils.processTemplateIntoString(template, map);
mail.setMsg(htmlText);
send(subject, htmlText, toEmail);
log.error("至" + toEmail + "的邮件发送成功");
} catch (Exception e) {
log.debug("邮件发送错误:" + e.getMessage());
}
}
use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.
the class TestEmailSender method sendTestEmail.
private boolean sendTestEmail(String email) {
HtmlEmail htmlEmail;
try {
htmlEmail = sendMailSsl.initializeMail(email);
} catch (EmailException e) {
logger.logException("Failed to create email for sample email:", e);
return false;
}
htmlEmail.setSubject("AuthMe test email");
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server (" + server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
return sendMailSsl.sendEmail(message, htmlEmail);
}
Aggregations