zoukankan      html  css  js  c++  java
  • 3000客接口迁移一记

    1.163邮件服务器 必须用465 ,不能用587和25端口

    2.阿里云已经禁用25端口使用邮件时需要加入ssl验证:

    public  void sendEmil(String to,String subject, String message) {  
                try {  
                    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());  
                    final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";  
                    //设置邮件会话参数  
                    Properties props = new Properties();  
                    //邮箱的发送服务器地址  
                    props.setProperty("mail.smtp.host", host);  
                    props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);  
                    props.setProperty("mail.smtp.socketFactory.fallback", "false");  
                    //邮箱发送服务器端口,这里设置为465端口  
                    props.setProperty("mail.smtp.port", "465");  
                    props.setProperty("mail.smtp.socketFactory.port", "465");  
                    props.put("mail.smtp.auth", "true");  
                    final String username = from;  
                    final String password = psw;  
                    //获取到邮箱会话,利用匿名内部类的方式,将发送者邮箱用户名和密码授权给jvm  
                    Session session = Session.getDefaultInstance(props, new Authenticator() {  
                        protected PasswordAuthentication getPasswordAuthentication() {  
                            return new PasswordAuthentication(username, password);  
                        }  
                    });  
                    //通过会话,得到一个邮件,用于发送  
                    Message msg = new MimeMessage(session);  
                    //设置发件人  
                    msg.setFrom(new InternetAddress(from));  
                    //设置收件人,to为收件人,cc为抄送,bcc为密送  
                    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));  
                    msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(to, false));  
                    msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(to, false));  
                    msg.setSubject(subject);  
                    //设置邮件消息  
                    msg.setText(message);  
                    //设置发送的日期  
                    msg.setSentDate(new Date());  
                      
                    //调用Transport的send方法去发送邮件  
                    Transport.send(msg);  
      
                } catch (Exception e) {  
                    e.printStackTrace();  
                }  
      
            }  

    3.将spring boot的test依赖删除,并注释Test类,在packge时不会运行代码。

  • 相关阅读:
    NOJ-1581 筷子 (线性DP)
    UVA-242 Stamps and Envelope Size (DP)
    POJ 1860 (SPFA判断正环)
    POJ 3268 最短路水题
    STL----priority_queue
    STL----unique
    POJ 2031(最小生成树Kruskal算法+几何判断)
    POJ 3468(线段树区间修改+区间求和)
    学习线段树
    POJ 1251(最小生成树裸题)
  • 原文地址:https://www.cnblogs.com/liter7/p/9153454.html
Copyright © 2011-2022 走看看