• java中邮件通知


    // 客户信息
            Tkhxx tkhxx = new Tkhxx();
    
    try {
                String msg = tkhxx.toString();
                MailUtil.simpleMailSend(MailUtil.mail_emp_username, "客户"+tkhxx.getKhh()+"注册,请审批", msg);
                Tqylxxx cs = this.getContactMail(bean.getProvinces(),bean.getCity(),bean.getArea());
                if(cs!=null && !CommonUtils.isEmpty(cs.getMail())) {
                    MailUtil.simpleMailSend(cs.getMail(), "客户"+tkhxx.getKhh()+"注册,请审批", msg);
                }
            }
            catch(Exception e) {
                System.out.println(e.getMessage());
            }
    
    
    
    package com.zw.wechat.utils;
    
    import java.util.Properties;
    
    import javax.mail.internet.MimeMessage;
    
    import org.springframework.mail.SimpleMailMessage;
    import org.springframework.mail.javamail.JavaMailSender;
    import org.springframework.mail.javamail.JavaMailSenderImpl;
    import org.springframework.mail.javamail.MimeMessageHelper;
    import org.springframework.scheduling.annotation.Async;
    
    public class MailUtil {
        // #服务器主机名
        public static String mail_host = "";
        // #发送邮箱地址
        public static String mail_username = "";
        // #你的授权码
        public static String mail_password = "";
        // #接受邮箱地址
        public static String mail_emp_username = "";
        // #接受邮箱地址
        public static String mail_mgr_username = "";
    
        public static String getMail_host() {
            return mail_host;
        }
    
        public static void setMail_host(String mail_host) {
            MailUtil.mail_host = mail_host;
        }
    
        public static String getMail_username() {
            return mail_username;
        }
    
        public static void setMail_username(String mail_username) {
            MailUtil.mail_username = mail_username;
        }
    
        public static String getMail_password() {
            return mail_password;
        }
    
        public static void setMail_password(String mail_password) {
            MailUtil.mail_password = mail_password;
        }
    
        public static String getMail_emp_username() {
            return mail_emp_username;
        }
    
        public static void setMail_emp_username(String mail_emp_username) {
            MailUtil.mail_emp_username = mail_emp_username;
        }
    
        public static String getMail_mgr_username() {
            return mail_mgr_username;
        }
    
        public static void setMail_mgr_username(String mail_mgr_username) {
            MailUtil.mail_mgr_username = mail_mgr_username;
        }
        
        public static JavaMailSender initJavaMailSender() {  
            Properties properties = new Properties();    
            //properties.setProperty("mail.debug", "true");// 是否显示调试信息(可选)    
            properties.setProperty("mail.smtp.auth", "true");    
            properties.put("mail.smtp.timeout", "25000");  
            JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();    
            javaMailSender.setJavaMailProperties(properties);    
            javaMailSender.setHost(MailUtil.mail_host);  
            javaMailSender.setUsername(MailUtil.mail_username); // username  
            javaMailSender.setPassword(MailUtil.mail_password); // password  
        
            javaMailSender.setDefaultEncoding("UTF-8");    
            return javaMailSender;    
        } 
    
        public static void sendText(JavaMailSender sender, String array, String subject, String msg) {
            SimpleMailMessage mailMessage = new SimpleMailMessage();
            mailMessage.setTo(array);
            mailMessage.setSubject("----" + subject + "----");
            mailMessage.setText(msg);
            sender.send(mailMessage);
        }
        
        public static void sendText(JavaMailSender sender, String array[], String subject, String msg) {
            SimpleMailMessage mailMessage = new SimpleMailMessage();
            mailMessage.setTo(array);
            mailMessage.setSubject("----" + subject + "----");
            mailMessage.setText(msg);
            sender.send(mailMessage);
        }
    
        public static void sendHtml(JavaMailSender sender, String array[], String subject, String msg) throws Exception {
            MimeMessage mailMessage = sender.createMimeMessage();
            MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "GBK");
            messageHelper.setTo(array);
            messageHelper.setSubject("----" + subject + "----");
            messageHelper.setText(msg, true);
            sender.send(mailMessage);
        }
    
        @Async
        public static void simpleMailSend(String email, String subject, String msg) {
            try {
                JavaMailSender sender = initJavaMailSender();
                if (email.contains(",")) {
                    String[] addr = email.split(",");
                    sendText(sender,addr,subject,msg);
                } else if (email.contains(";")) {
                    String[] addr = email.split(";");
                    sendText(sender,addr,subject,msg);
                } else {
                    sendText(sender,email,subject,msg);
                }
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
    
    }
  • 相关阅读:
    day72日考
    项目开发流程
    js 之 JSON详解
    MySQL 中的 FOUND_ROWS() 与 ROW_COUNT() 函数
    mysql 之 函数
    liunx 之 Ubuntu 网速慢解决方法
    js 之 object
    js 之 箭头函数 (未学完)
    java 之 学习过程中遇到的大佬博客
    java 之 enum(枚举)
  • 原文地址:https://www.cnblogs.com/xianz666/p/13084788.html
Copyright © 2020-2023  润新知