Итак, я вижу что-то странное с моим проектом. У меня есть код, работающий локально, и все работает нормально, у меня есть следующий код, который отправляет следующее электронное письмо в 10 утра каждый день. Локально это работает, когда размещается и запускается вживую на Tomcat, в результате получается 4 электронных письма. Два содержат старое сообщение электронной почты, которое я удалил из кода несколько месяцев назад, и два сообщения электронной почты, отправляющие правильное новое сообщение с подробной информацией об истекающей политике. Я не думаю, что с моим кодом что-то не так, поскольку он работает нормально локально, а старое сообщение электронной почты не существует, поэтому я думаю, что это должно быть проблемой с развернутым новым кодом на Tomcat. Кто-нибудь сталкивался с чем-то подобным и имел представление о том, почему это происходит? Я искал распакованные военные файлы на Tomcat и нигде не могу найти старого сообщения электронной почты, поэтому я не знаю, с чего начать отладку этого ...
@Scheduled(cron= "0 0 10 * * ?") //everyday at 10:00am
public void sendLicReminder(){
Mail mail = new Mail();
mail.setFrom("no-reply@test.com");
mail.setSubject("Affiliate - Policy Renewal Notice");
Map<String, Object> mailModel = new HashMap<String, Object>();
mail.setModel(mailModel);
List<License> licenses=licenseRepository.findAll();
for(License lic: licenses){
if (lic.getExpiration().minusDays(30).isEqual(LocalDate.now())){
try {
mail.setTo(new String[]{lic.getClient().getEmail()});
emailService.sendSimpleMessage(mail, lic);
} catch (Exception e) {
e.printStackTrace();
}
}
}
List<Insurance> insurances = insuranceRepository.findAll();
for(Insurance insur:insurances){
if ( insur.getExpiration().minusDays(30).isEqual( LocalDate.now() ) ){
try {
mail.setTo(new String[]{insur.getClient().getEmail()});
emailService.sendSimpleMessage(mail, insur);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
шаблон электронной почты:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML Reminder Email</title>
<style type="text/css">
body {margin: 0; padding: 0; min-width: 100%!important;}
img {height: auto;}
.content {width: 100%; max-width: 600px; margin-top: 10%;}
.header {padding: 40px 30px 20px 30px;}
.innerpadding {padding: 30px 30px 30px 30px;}
a{color: #6435c9; text-decoration: none;}
.borderbottom {border-bottom: 1px solid #f2eeed;}
.subhead {text-align: center; font-size: 18px; color: #ffffff; font-family: sans-serif; letter-spacing: 5px;}
.h1, .h2, .h3, .bodycopy {color: #0a0514; font-family: sans-serif;}
.h1 {font-size: 33px; line-height: 38px; font-weight: bold;}
.h2 {padding: 0 0 15px 0; font-size: 24px; line-height: 28px; font-weight: bold;}
.bodycopy {font-size: 14px; font-family: sans-serif; line-height: 24px; margin-bottom: 15px;}
.button {text-align: center; font-size: 18px; font-family: sans-serif; font-weight: bold; padding: 0 30px 0 30px;}
.button a {color: #ffffff; text-decoration: none;}
.footer {padding: 20px 30px 15px 30px;}
.footercopy {font-family: sans-serif; font-size: 14px; color: #ffffff;}
.footercopy a {color: #ffffff; text-decoration: underline;}
@media only screen and (max-width: 550px), screen and (max-device-width: 550px) {
body[yahoo] .hide {display: none!important;}
body[yahoo] .buttonwrapper {background-color: transparent!important;}
body[yahoo] .button {padding: 0px!important;}
body[yahoo] .button a {background-color: #e05443; padding: 15px 15px 13px!important;}
body[yahoo] .unsubscribe {display: block; margin-top: 20px; padding: 10px 50px; background: #2f3942; border-radius: 5px; text-decoration: none!important; font-weight: bold;}
}
/*@media only screen and (min-device-width: 601px) {
.content {width: 600px !important;}
.col425 {width: 425px!important;}
.col380 {width: 380px!important;}
}*/
</style>
</head>
<body bgcolor="#f6f8f1">
<table width="100%" bgcolor="#f6f8f1" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<!--[if (gte mso 9)|(IE)]>
<table width="600" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<![endif]-->
<table bgcolor="#ffffff" class="content" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#6435c9" class="header">
<table width="70" align="left" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="70" style="padding: 0 20px 20px 0;">
<img class="fix" src="cid:Mail_Icon.png" width="70" height="70" border="0" alt="" />
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
<table width="425" align="left" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<![endif]-->
<table class="col425" align="left" border="0" cellpadding="0" cellspacing="0" style="width: 100%; max-width: 425px;">
<tr>
<td height="70">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="subhead" style="padding: 0">
Policy Expiration Reminder
</td>
</tr>
</table>
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
<tr>
<td class="innerpadding borderbottom">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<th:block th:switch="${license==null}" class="emailRow">
<div th:case="true">
<tr class="emailRow">
<td class="bodycopy" th:text="${insurance.client.principleName}"></td>
</tr>
<tr class="emailRow">
<p class="bodycopy" th:inline="text">Our Records indicate that your [[${insurance.type}]] policy, listed below, is up for renewal in 30 days. </p>
</tr>
<tr>
<span><b>Type: </b></span><span th:text="${insurance.type}"></span><br/>
<span><b>Expiration Date: </b> </span><span th:text="${insurance.expiration}"></span><br/>
<span><b>Limits: </b></span><span th:text="${insurance.limits}"></span><br/>
<span><b>Carrier: </b></span><span th:text="${insurance.carrier}"></span><br/>
</tr>
</div>
<div th:case="false">
<tr class="emailRow">
<td class="bodycopy" th:text="${license.client.principleName}"></td>
</tr>
<tr class="emailRow">
<p class="bodycopy" th:inline="text">Our Records indicate that your [[${license.type}]] policy, listed below, is up for renewal in 30 days. Please provide the updated document(s). We appreciate your compliance. </p>
</tr>
<tr>
<span><b>Type: </b></span><span th:text="${license.type}"></span> <br/>
<span><b>Expiration Date: </b></span><span th:text="${license.expiration}"></span><br/>
<span><b>State: </b></span><span th:text="${license.state}"></span><br/>
<span><b>File Name: </b></span><span th:text="${license.license}"></span><br/>
</tr>
</div>
</th:block>
<tr>
<br/>
<p class="bodycopy">Thank you,</p>
<p class="bodycopy"> Test Services</p>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Вот служба электронной почты, которую я использую для помощи в отправке почтового шаблона:
public void sendSimpleMessage(Mail mail, @ModelAttribute(value="lic")License license) throws MessagingException, IOException {
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message,
MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name());
helper.addAttachment("Mail_Icon.png", new ClassPathResource("static/images/Mail_Icon.png"));
Context context = new Context();
context.setVariables(mail.getModel());
context.setVariable("license",license);
String html = templateEngine.process("emailMessage", context);
helper.setTo(mail.getTo());
helper.setText(html, true);
helper.setSubject(mail.getSubject());
helper.setFrom(mail.getFrom());
javaMailSender.send(message);
}
public void sendSimpleMessage(Mail mail, @ModelAttribute(value="insur")Insurance insurance) throws MessagingException, IOException {
MimeMessage message = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message,
MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name());
helper.addAttachment("Mail_Icon.png", new ClassPathResource("static/images/Mail_Icon.png"));
Context context = new Context();
context.setVariables(mail.getModel());
context.setVariable("insurance",insurance);
String html = templateEngine.process("emailMessage", context);
helper.setTo(mail.getTo());
helper.setText(html, true);
helper.setSubject(mail.getSubject());
helper.setFrom(mail.getFrom());
javaMailSender.send(message);
}