Commit bc1dac47 by guanchen

更新发邮件端口

parent 45b5a8e5
......@@ -11,8 +11,8 @@
</parent>
<groupId>com.lanren.huhu</groupId>
<artifactId>report_expand</artifactId>
<!--<artifactId>report_mail</artifactId>-->
<!--<artifactId>report_expand</artifactId>-->
<artifactId>report_mail</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>partner</name>
<description>呼呼省钱合伙人相关服务</description>
......
......@@ -41,6 +41,6 @@ public class ReportPartnerApplication implements ApplicationRunner {
public void run(ApplicationArguments args) throws Exception {
logger.info("profile active is {}", profilesActive);
// agentDailyExpandTask.runExpandPartner();
// agentDailyMailTask.runExpandCity2ndAgentMail();
agentDailyMailTask.runExpandCity2ndAgentMail();
}
}
......@@ -12,9 +12,11 @@ import com.lanren.huhu.partner.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSendException;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.mail.SendFailedException;
import java.util.*;
/**
......@@ -58,13 +60,11 @@ public class AgentDailyMailTask {
private String buildMailContent(Integer agentId) {
Date yesterday = DateUtils.getDateBefore(new Date(), 1);
long now = System.currentTimeMillis();
Date yesterdayBegin = new Date(yesterday.getTime() - yesterday.getTime() % (24 * 60 * 60 * 1000L));
Date yesterdayEnd = new Date(yesterdayBegin.getTime() + (24 * 60 * 60 - 1) * 1000L);
Date monthBegin = new Date(DateUtils.getMonth1stTimestamp(now));
Date monthEnd = new Date(DateUtils.getMonthLastTimestamp(now));
String yesterdayStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT);
String yesterdayBeginStr = DateUtils.format(yesterdayBegin, DateUtils.FORMAT_LONG);
String yesterdayEndStr = DateUtils.format(yesterdayEnd, DateUtils.FORMAT_LONG);
String yesterdayBeginStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT) + " 00:00:00";
String yesterdayEndStr = DateUtils.format(yesterday, DateUtils.FORMAT_SHORT) + " 23:59:59";
String monthBeginStr = DateUtils.format(monthBegin, DateUtils.FORMAT_LONG);
String monthEndStr = DateUtils.format(monthEnd, DateUtils.FORMAT_LONG);
StringBuilder sb = new StringBuilder();
......@@ -240,6 +240,20 @@ public class AgentDailyMailTask {
}
break;
} catch (Exception e) {
logger.error(e.getMessage(), e);
if (e instanceof MailSendException) {
Exception[] messageExceptions = ((MailSendException) e).getMessageExceptions();
SendFailedException sendFail;
try {
sendFail = (SendFailedException) messageExceptions[0];
} catch (ClassCastException ee) {
logger.error("class cast exception:[{}]", ee.getMessage());
return;
}
logger.error("send mail eerror,the invalid mail address:{}", sendFail.getInvalidAddresses());
}
logger.error("发送邮件失败, 第{}次", i);
}
}
......
......@@ -3,7 +3,6 @@ package com.lanren.huhu.partner.service.impl;
import com.lanren.huhu.partner.service.IMailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
......@@ -28,55 +27,64 @@ public class IMailServiceImpl implements IMailService {
/**
* Spring Boot 提供了一个发送邮件的简单抽象,使用的是下面这个接口,这里直接注入即可使用
*/
@Autowired
private JavaMailSenderImpl mailSender;
// @Autowired
// private JavaMailSenderImpl mailSender;
/**
* 配置
*/
@Value("${spring.mail.host}")
private String host;
@Value("${spring.mail.username}")
private String username;
@Value("${spring.mail.password}")
private String password;
@Value("${spring.mail.port}")
private String port;
@Value("${spring.mail.from}")
private String from;
@Value("${spring.mail.smtp.host}")
private String host;
@Override
public void sendMail(String subject, String text, File attachment, String[] tos) throws MessagingException {
MimeMessage mailMessage = configMailMessage();
configMessageHelper(mailMessage, subject, text, attachment, tos, new String[]{});
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host);
mailSender.setUsername(username);
mailSender.setPassword(password);
mailSender.setPort(465);
mailSender.setDefaultEncoding("UTF-8");
Properties javaMailProperties = new Properties();
javaMailProperties.setProperty("mail.smtp.auth", "true");
javaMailProperties.setProperty("mail.smtp.timeout", "25000");
javaMailProperties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
javaMailProperties.setProperty("mail.smtp.socketFactory.fallback", "false");
javaMailProperties.setProperty("mail.smtp.socketFactory.port", "465");
mailSender.setJavaMailProperties(javaMailProperties);
MimeMessage mailMessage = mailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8");
mimeMessageHelper.setFrom(from);
mimeMessageHelper.setSubject(subject);
mimeMessageHelper.setText(text, true);
if (attachment != null) {
mimeMessageHelper.addAttachment(attachment.getName(), attachment);
}
mimeMessageHelper.setTo(tos);
mailSender.send(mailMessage);
}
@Override
public void sendMailWithCc(String subject, String text, File attachment, String[] tos, String[] cc) throws MessagingException {
MimeMessage mailMessage = configMailMessage();
MimeMessageHelper mimeMessageHelper = configMessageHelper(mailMessage, subject, text, attachment, tos, new String[]{});
mimeMessageHelper.setCc(cc);
mailSender.send(mailMessage);
}
private MimeMessage configMailMessage() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host);
mailSender.setPort(Integer.parseInt(port));
mailSender.setUsername(username);
mailSender.setPassword(password);
mailSender.setPort(465);
mailSender.setDefaultEncoding("UTF-8");
Properties javaMailProperties = new Properties();
javaMailProperties.setProperty("mail.smtp.auth", "true");
javaMailProperties.setProperty("mail.smtp.timeout", "25000");
javaMailProperties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
javaMailProperties.setProperty("mail.smtp.socketFactory.fallback", "false");
javaMailProperties.setProperty("mail.smtp.socketFactory.port", "465");
mailSender.setJavaMailProperties(javaMailProperties);
return mailSender.createMimeMessage();
}
private MimeMessageHelper configMessageHelper(MimeMessage mailMessage, String subject, String text, File attachment, String[] tos, String[] cc)
throws MessagingException {
MimeMessage mailMessage = mailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8");
mimeMessageHelper.setFrom(from);
mimeMessageHelper.setSubject(subject);
......@@ -85,7 +93,7 @@ public class IMailServiceImpl implements IMailService {
mimeMessageHelper.addAttachment(attachment.getName(), attachment);
}
mimeMessageHelper.setTo(tos);
return mimeMessageHelper;
mimeMessageHelper.setCc(cc);
mailSender.send(mailMessage);
}
}
......@@ -60,15 +60,11 @@ spring:
preferred-json-mapper: fastjson
#邮箱配置
mail:
host: smtp.exmail.qq.com #发送邮件服务器
username: report@wasair.com #发送邮件的邮箱地址
password: Wasai123 #客户端授权码,不是邮箱密码,这个在qq邮箱设置里面自动生成的
port: 25 #端口号465或587
from: report@wasair.com # 发送邮件的地址,和上面username一致
properties:
mail:
smtp:
auth: true
host: smtp.exmail.qq.com
# properties.mail.smtp.starttls.enable: true
# properties.mail.smtp.starttls.required: true
# properties.mail.smtp.ssl.enable: true
......
......@@ -200,14 +200,14 @@
SELECT
'Vip会员' c1,
case when b.invite_user_id = a.user_id then '直接' else '间接' end c2,
COUNT(a.recharge_time between #{yesterdayBegin} and #{yesterdayEnd} or NULL) c3,
COUNT(a.recharge_time >= '2019-08-16 23:59:59' or NULL) c4,
COUNT(a.recharge_time between #{monthBegin} and #{monthEnd} or NULL) c5,
COUNT(c.become_high_time between #{yesterdayBegin} and #{yesterdayEnd} or NULL) c3,
COUNT(c.become_high_time >= '2019-08-16 23:59:59' or NULL) c4,
COUNT(c.become_high_time between #{monthBegin} and #{monthEnd} or NULL) c5,
COUNT(*) c6
FROM agent_reward a
LEFT JOIN partner_invite_relation b on a.source_user_id=b.user_id
FROM agent_expand_detail a
JOIN partner_invite_relation b on a.expand_user_id=b.user_id
JOIN partner_account c on a.expand_user_id=c.user_id and c.is_super_partner=0 and c.partner_level=20
WHERE a.agent_id = #{agentId}
AND a.reward_type in (30,20,710,720,730)
GROUP BY 1,2
</select>
<insert id="insertByDetail">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment