• Apache-SimpleEmail 简单应用


    比JavaMail使用方法要直接,jar包只需要在JavaMail的基础上添加commons-email-1.4.jar即可。

    代码:

    // QQ邮箱发送邮件
    SimpleEmail simpleEmail = new SimpleEmail();
    simpleEmail.setHostName("smtp.qq.com");
    simpleEmail.setAuthentication("3******8", "g*****ai");
    simpleEmail.setSmtpPort(587);
    simpleEmail.setFrom("3********@qq.com", "y****", "UTF-8");
    simpleEmail.addTo(email, name);
    simpleEmail.setSubject("title");
    simpleEmail.setMsg("content");
    simpleEmail.send();
    					    
    System.out.println("发送邮件成功!");
    
    // 网易邮箱发送邮件
    SimpleEmail simpleEmail = new SimpleEmail();
    simpleEmail.setHostName("smtp.163.com");
    simpleEmail.setAuthentication("y*******@163.com", "y********");
    simpleEmail.setSmtpPort(25);
    simpleEmail.setFrom("y*******@163.com", "y*", "UTF-8");
    simpleEmail.addTo("3**********@qq.com", "c**************");
    simpleEmail.setSubject("网易邮箱测试");
    simpleEmail.setMsg("网易邮箱测试网易邮箱测试网易邮箱测试");
    simpleEmail.send();
    System.out.println("发送成功");
    
    // 发送带附件的邮件
    // 附件
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath("D:\testEXC.xlsx");
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription("excel文件");
    attachment.setName("MyExcel.xlsx");
    // 邮件
    MultiPartEmail simpleEmail = new MultiPartEmail();
    simpleEmail.setHostName("smtp.163.com");
    simpleEmail.setAuthentication("y***********@163.com", "y********");
    simpleEmail.setSmtpPort(25);
    simpleEmail.setFrom("y*********@163.com", "y*", "UTF-8");
    simpleEmail.addTo("3**************@qq.com", "c***********");
    simpleEmail.setSubject("带附件");
    simpleEmail.setMsg("带附件的邮件测试");
    simpleEmail.attach(attachment);
    simpleEmail.send();
    System.out.println("发送成功");
    

      

  • 相关阅读:
    在ModelSim中添加Xilinx仿真库
    关于DDR3非常棒的文章
    Modelsim编译Xilinx器件库的另一种方法
    FPGA按键去抖verilog代码
    DDOS与DDOS追踪的介绍
    自动实时监控Windows2003服务器终端登录
    Java 如何实现线程间通信
    C# 获取FormData数据
    利用 FormData 对象发送 Key/Value 对的异步请求
    jdk初始安装配置
  • 原文地址:https://www.cnblogs.com/loveflycforever/p/5862389.html
Copyright © 2020-2023  润新知