use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.
the class MailSenderAutoConfigurationTests method smtpHostWithJavaMailProperties.
@Test
public void smtpHostWithJavaMailProperties() {
load(EmptyConfig.class, "spring.mail.host:localhost", "spring.mail.properties.mail.smtp.auth:true");
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context.getBean(JavaMailSender.class);
assertThat(bean.getJavaMailProperties().get("mail.smtp.auth")).isEqualTo("true");
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project coprhd-controller by CoprHD.
the class MailHelper method createJavaMailSender.
private JavaMailSenderImpl createJavaMailSender() {
Map<String, String> properties = getPropertiesFromCoordinator();
smtpServer = properties.get(SMTP_SERVER);
smtpPort = properties.get(SMTP_PORT);
smtpEnableTls = properties.get(SMTP_ENABLE_TLS);
fromAddress = properties.get(SMTP_FROM_ADDRESS);
smtpAuthType = properties.get(SMTP_AUTH_TYPE);
username = properties.get(SMTP_USERNAME);
password = properties.get(SMTP_PASSWORD);
boolean enableTls = StringUtils.equalsIgnoreCase("yes", smtpEnableTls);
boolean authEnabled = StringUtils.isNotBlank(smtpAuthType) && !StringUtils.equalsIgnoreCase(smtpAuthType, "none");
Properties javaMailProperties = new Properties();
javaMailProperties.setProperty("mail.smtp.host", smtpServer);
javaMailProperties.setProperty("mail.smtp.connectiontimeout", SMTP_CONNECTION_TIMEOUT);
javaMailProperties.setProperty("mail.smtp.timeout", SMTP_READ_TIMEOUT);
javaMailProperties.setProperty("mail.smtp.writetimeout", SMTP_WRITE_TIMEOUT);
if (enableTls) {
javaMailProperties.setProperty("mail.smtp.channel", "starttls");
smtpPort = defaultPort(smtpPort, DEFAULT_SMTP_TLS_PORT);
} else {
smtpPort = defaultPort(smtpPort, DEFAULT_SMTP_PORT);
}
javaMailProperties.setProperty("mail.smtp.port", smtpPort);
javaMailProperties.setProperty("mail.smtp.from", fromAddress);
if (authEnabled) {
javaMailProperties.setProperty("mail.smtp.auth", "true");
javaMailProperties.setProperty("mail.smtp.user", username);
javaMailProperties.setProperty("mail.smtp.pass", password);
}
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(smtpServer);
try {
mailSender.setPort(Integer.parseInt(smtpPort));
} catch (NumberFormatException e) {
log.error(String.format("Failed to parse smtp port [%s]", smtpPort), e);
}
// this.mailSender.setProtocol(protocol);
if (authEnabled) {
mailSender.setUsername(username);
mailSender.setPassword(password);
}
mailSender.setJavaMailProperties(javaMailProperties);
log.debug(String.format(" mail.smtp.host = %s", mailSender.getJavaMailProperties().get("mail.smtp.host")));
log.debug(String.format(" mail.smtp.port = %s", mailSender.getJavaMailProperties().get("mail.smtp.port")));
log.debug(String.format(" mail.smtp.channel = %s", mailSender.getJavaMailProperties().get("mail.smtp.channel")));
log.debug(String.format(" mail.smtp.auth = %s", mailSender.getJavaMailProperties().get("mail.smtp.auth")));
log.debug(String.format(" mail.smtp.user = %s", mailSender.getJavaMailProperties().get("mail.smtp.user")));
log.debug(String.format(" mail.smtp.from = %s", mailSender.getJavaMailProperties().get("mail.smtp.from")));
return mailSender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project ocvn by devgateway.
the class EmailServiceConfiguration method javaMailSenderImpl.
@Bean
public JavaMailSenderImpl javaMailSenderImpl() {
JavaMailSenderImpl jmsi = new JavaMailSenderImpl();
jmsi.setHost("localhost");
jmsi.setPort(SMTP_PORT);
return jmsi;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project xmall by Exrick.
the class EmailUtil method sendEmailDealThank.
@Async
public void sendEmailDealThank(String sendTo, String title, String tokenName, String token, TbThanks tbThanks) {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设定邮箱服务器配置
senderImpl.setHost(EMAIL_HOST);
senderImpl.setUsername(EMAIL_USERNAME);
senderImpl.setPassword(EMAIL_PASSWORD);
Properties prop = new Properties();
// 服务器进行认证
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.timeout", "20000");
// qq邮箱需开启
prop.put("mail.smtp.ssl.enable", "true");
senderImpl.setJavaMailProperties(prop);
// 发送html邮件
MimeMessage mailMessage = senderImpl.createMimeMessage();
MimeMessageHelper messageHelper = null;
// 设置邮件内容
try {
messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8");
messageHelper.setTo(sendTo);
messageHelper.setFrom(EMAIL_SENDER);
messageHelper.setSubject(title);
// true表示HTML格式的邮件
String content = "尊敬的管理员Exrick您好,您收到了来自" + title + "确认订单,请您及时处理:<br>";
content += "-------------------------------------<br>";
content += "登录账号:" + tbThanks.getUsername() + "<br>";
content += "用户昵称:" + tbThanks.getNickName() + "<br>";
content += "捐赠金额:" + tbThanks.getMoney() + "<br>";
content += "支付方式:" + tbThanks.getPayType() + "<br>";
content += "留言:" + tbThanks.getInfo() + "<br>";
content += "通知邮箱:" + tbThanks.getEmail() + "<br>";
content += "订单ID:" + tbThanks.getOrderId() + "<br>";
content += "支付时间:" + tbThanks.getTime() + "<br>";
content += "-------------------------------------<br>";
content += "请点击以下相应链接完成对应处理操作:<br><br>";
String passUrl = SERVER_URL + "/pay/pass?tokenName=" + tokenName + "&token=" + token + "&id=" + tbThanks.getId();
content += "审核通过并展示捐赠数据:<br><a href='" + passUrl + "'>" + passUrl + "</a><br><br>";
String backUrl = SERVER_URL + "/pay/back?tokenName=" + tokenName + "&token=" + token + "&id=" + tbThanks.getId();
content += "审核驳回:<br><a href='" + backUrl + "'>" + backUrl + "</a><br><br>";
String notShowUrl = SERVER_URL + "/pay/passNotShow?tokenName=" + tokenName + "&token=" + token + "&id=" + tbThanks.getId();
content += "审核通过但不展示捐赠数据:<br><a href='" + notShowUrl + "'>" + notShowUrl + "</a><br><br>";
String editUrl = SERVER_URL + "/pay-edit?tokenName=" + tokenName + "&token=" + token + "&id=" + tbThanks.getId();
content += "编辑捐赠数据:<br><a href='" + editUrl + "'>" + editUrl + "</a><br><br>";
System.out.println(editUrl);
String delUrl = SERVER_URL + "/pay/del?tokenName=" + tokenName + "&token=" + token + "&id=" + tbThanks.getId();
content += "删除该捐赠数据:<br><a href='" + delUrl + "'>" + delUrl + "</a><br><br>";
messageHelper.setText(content, true);
} catch (MessagingException e) {
e.printStackTrace();
}
// 发送邮件
senderImpl.send(mailMessage);
log.info("用户:" + tbThanks.getUsername() + " 支付:" + tbThanks.getMoney() + "元 待审核的邮件发送成功");
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project xmall by Exrick.
the class EmailUtil method sendEmailPayResult.
@Async
public void sendEmailPayResult(String sendTo, String title, String content) {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设定邮箱服务器配置
senderImpl.setHost(EMAIL_HOST);
senderImpl.setUsername(EMAIL_USERNAME);
senderImpl.setPassword(EMAIL_PASSWORD);
Properties prop = new Properties();
// 服务器进行认证
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.timeout", "20000");
// qq邮箱需开启
prop.put("mail.smtp.ssl.enable", "true");
senderImpl.setJavaMailProperties(prop);
// 发送html邮件
MimeMessage mailMessage = senderImpl.createMimeMessage();
MimeMessageHelper messageHelper = null;
// 设置邮件内容
try {
messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8");
messageHelper.setTo(sendTo);
messageHelper.setFrom(EMAIL_SENDER);
messageHelper.setSubject(title);
// true表示HTML格式的邮件
messageHelper.setText(content, true);
} catch (MessagingException e) {
e.printStackTrace();
}
// 发送邮件
senderImpl.send(mailMessage);
log.info("给 " + sendTo + " 的审核结果邮件发送成功");
}
Aggregations