zoukankan      html  css  js  c++  java
  • java邮件发送小实例

    mail.properties

    #邮箱服务器
    mail.host.name=smtp.163.com
    #发送方用户名
    mail.username=**@163.com
    #用户名
    mail.password=**
    #接收方
    mail.to=**@qq.com
    #发送方
    mail.from=**@163.com

    代码如下:

    /**
         * 发送邮件
         */
        public void sendMail(String email, Phonefee phonefee) throws Exception {
            // 读取mail.properties
            ResourceBundle bundle = PropertyResourceBundle.getBundle("mail");
            String host = bundle.getString("mail.host.name");
            String username = bundle.getString("mail.username");
            String password = bundle.getString("mail.password");
            String from = bundle.getString("mail.from");
    
        
         //接收方 Collection collection = new ArrayList<InternetAddress>(); collection.add(new InternetAddress(email)); HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setCharset("utf-8"); htmlEmail.setSubject("中国移动手机话费"); htmlEmail.setFrom(from, "中国移动", "gbk"); htmlEmail.setTo(collection); htmlEmail.setSentDate(Calendar.getInstance().getTime());

         //接收邮件内容 htmlEmail.setHtmlMsg(phonefee.getDatacontent());
    htmlEmail.setDebug(
    false); htmlEmail.setHostName(host); htmlEmail.setAuthentication(username, password); htmlEmail.send(); }
  • 相关阅读:
    leetcode78 Subsets
    leetcode76 Minimum Window Substring
    leetcode73 Set Matrix Zeroes
    leetcode70 Climbing Stairs
    leetcode50 Pow(x, n)
    leetcode49 Group Anagrams
    leetcode48 Rotate Image
    正则表达式及字符处理
    RPM软件包管理.作业
    yum管理RPM包.作业
  • 原文地址:https://www.cnblogs.com/sfeng1825/p/2765855.html
Copyright © 2011-2022 走看看