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(); }
  • 相关阅读:
    stl rope
    vijos1574 摇钱树
    图论 Dijkstra+堆优化
    c++输入优化
    Vijos1579 宿命的PSS 最小生成树
    快速求n阶多项式乘积
    c++stl map
    C#函数式程序设计之惰性列表工具——迭代器
    C#函数式程序设计之泛型(下)
    C#函数式程序设计之泛型(上)
  • 原文地址:https://www.cnblogs.com/sfeng1825/p/2765855.html
Copyright © 2011-2022 走看看