Explorar el Código

:ghost: 值日提醒调整
:sparkles: 美国某客户邮件推送

Ritchie hace 1 año
padre
commit
0a6598669e

+ 2 - 2
src/main/java/com/szwl/controller/ScheduledService.java

@@ -112,9 +112,9 @@ public class ScheduledService {
     public void scheduled() {
         if (isDo()) {
             Calendar calendar = Calendar.getInstance();
-            int number = calendar.get(Calendar.DAY_OF_WEEK);
+            int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
             // 如果不是周日 1
-            if (number != 1) {
+            if (dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY) {
                 tDepartmentService.onTime();
             }
         }

+ 13 - 6
src/main/java/com/szwl/controller/TMessageCodeController.java

@@ -71,12 +71,14 @@ public class TMessageCodeController {
         if (currentTime - lastTime < 10 * 60 * 1000) {
             return R.fail("请勿频繁发送,10分钟后再试");
         }
-        String SZ = "Sunzee";
+//        String SZ = "Sunzee";
+        String SC = "Sevencloud";
+        String AETI = "Portalmcc";
         String companyType = "";
-        if (StringUtils.isNotEmpty(hostName) && SZ.equals(hostName)) {
-            companyType = "0";
-        } else {
+        if (SC.equals(hostName)) {
             companyType = "1";
+        } else {
+            companyType = "0";
         }
         // 如果是国内
         if (ifForeign.equals("0")) {
@@ -120,8 +122,13 @@ public class TMessageCodeController {
                 return R.fail(ResponseCodesEnum.A0207, "用户邮箱已存在");
             }
             //海外发邮件验证码
-            String result = tMessageCodeService.sendEmailAbroad("0", phoneOrEmail);
-            return R.ok(result);
+            if (AETI.equals(hostName)) {  // 美国孙总域名
+                String s = tMessageCodeService.sendEmailPortalmcc("0", phoneOrEmail);
+                return R.ok(s);
+            } else {
+                String result = tMessageCodeService.sendEmailAbroad("0", phoneOrEmail);
+                return R.ok(result);
+            }
         }
     }
 

+ 75 - 9
src/main/java/com/szwl/model/utils/SampleMail.java

@@ -7,15 +7,7 @@ import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.util.Properties;
 import java.util.UUID;
-//import java.util.HashMap;
-//import java.util.Base64;
-//import com.google.gson.GsonBuilder;
-//import javax.activation.DataHandler;
-//import javax.activation.FileDataSource;
-//import java.net.URL;
-//import java.net.URLEncoder;
-//import javax.activation.DataHandler;
-//import javax.activation.URLDataSource;
+
 
 public class SampleMail {
     protected static String genMessageID(String mailFrom) {
@@ -103,6 +95,80 @@ public class SampleMail {
         }
 
     }
+
+
+    public void sendAuthCodePortalmcc(String toEmail, String content) {
+        // 配置发送邮件的环境属性
+        final Properties props = new Properties();
+
+        // 表示SMTP发送邮件,需要进行身份验证
+        props.put("mail.smtp.auth", "true");
+        props.put("mail.smtp.host", "smtpdm.aliyun.com");  //华东1:smtpdm.aliyun.com,悉尼:smtpdm-ap-southeast-2.aliyun.com,(美国(原悉尼)):smtpdm-us-east-1.aliyuncs.com
+        //设置端口:
+        props.put("mail.smtp.port", "80");  //或"25"
+        props.put("mail.smtp.from", "support@portalmcc.com.cn");  //mailfrom 参数
+        props.put("mail.user", "support@portalmcc.com.cn");  // 发件人的账号(在控制台创建的发信地址)
+        props.put("mail.password", "DirectMail321");  // 发信地址的smtp密码(在控制台选择发信地址进行设置)
+        System.setProperty("mail.mime.splitlongparameters", "false");  //用于解决附件名过长导致的显示异常
+
+        // 构建授权信息,用于进行SMTP进行身份验证
+        Authenticator authenticator = new Authenticator() {
+            @Override
+            protected PasswordAuthentication getPasswordAuthentication() {
+                // 用户名、密码
+                String userName = props.getProperty("mail.user");
+                String password = props.getProperty("mail.password");
+                return new PasswordAuthentication(userName, password);
+            }
+        };
+        //使用环境属性和授权信息,创建邮件会话
+        Session mailSession = Session.getInstance(props, authenticator);
+        //mailSession.setDebug(true);  //开启debug模式
+
+
+        final String messageIDValue = genMessageID(props.getProperty("mail.user"));
+        //创建邮件消息
+        MimeMessage message = new MimeMessage(mailSession) {
+            @Override
+            protected void updateMessageID() throws MessagingException {
+                //设置自定义Message-ID值
+                setHeader("Message-ID", messageIDValue);  //创建Message-ID
+            }
+        };
+
+        try {
+            // 设置发件人邮件地址和名称。填写控制台配置的发信地址。和上面的mail.user保持一致。名称用户可以自定义填写。
+            InternetAddress from = new InternetAddress("support@portalmcc.com.cn", "Cotton Candy Robot");  //from 参数,可实现代发,注意:代发容易被收信方拒信或进入垃圾箱。
+            message.setFrom(from);
+
+            //可选。设置回信地址
+            Address[] a = new Address[1];
+            a[0] = new InternetAddress(toEmail);
+            message.setReplyTo(a);
+
+            // 设置收件人邮件地址
+            InternetAddress to = new InternetAddress(toEmail);
+            message.setRecipient(MimeMessage.RecipientType.TO, to);
+
+
+            message.setSentDate(new Date());  //设置时间
+
+            //设置邮件标题
+            message.setSubject("Verification Code");
+            message.setContent(content, "text/html;charset=UTF-8");  //html超文本;// "text/plain;charset=UTF-8" //纯文本。
+            // 发送邮件
+            Transport.send(message);
+
+        } catch (MessagingException e) {
+            String err = e.getMessage();
+            // 在这里处理message内容, 格式是固定的
+            System.out.println(err);
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+    }
+
 //    public static void main(String[] args) {
 //        // 配置发送邮件的环境属性
 //        final Properties props = new Properties();

+ 2 - 0
src/main/java/com/szwl/service/TMessageCodeService.java

@@ -27,4 +27,6 @@ public interface TMessageCodeService extends MyIService<TMessageCode> {
     String sendEmailAbroad(String type, String email);
 
     Date getLastSendTime(String phoneOrEmail);
+
+    String sendEmailPortalmcc(String type, String email);
 }

+ 17 - 0
src/main/java/com/szwl/service/impl/TMessageCodeServiceImpl.java

@@ -109,6 +109,23 @@ public class TMessageCodeServiceImpl extends ServiceImpl<TMessageCodeMapper, TMe
         return lastSendTime != null ? lastSendTime : new Date(0);
     }
 
+    @Override
+    public String sendEmailPortalmcc(String type, String email) {
+        String code = addCode();
+        String contnet = "";
+        contnet = getContnet(type,code);
+        new SampleMail().sendAuthCodePortalmcc(email, contnet);
+        TMessageCode tMessageCode = new TMessageCode();
+        tMessageCode.setType(type);
+        tMessageCode.setCode(code);
+        tMessageCode.setPhone(email);
+        tMessageCode.setModifyDate(new Date());
+        tMessageCode.setCreateDate(new Date());
+        tMessageCode.setStatus("0");
+        tMessageCodeMapper.insert(tMessageCode);
+        return "Send Success";
+    }
+
     //邮件标题
     private String getSubject(String type) {
         String subject = "";