zoukankan      html  css  js  c++  java
  • 邮箱验证

    一、简介 

    Commons Email封装了javamail,使用非常简单。
    功能:简单文本邮件、带附件的邮件、HTML格式的邮件
    官方首页:http://commons.apache.org/email/,目前最新版本是1.1
    官方示例:http://commons.apache.org/email/userguide.html

    使用前需引入3个jar文件:commons-email-1.1.jar、javamail.jar、activation.jar

    二、简单文本邮件

        SimpleEmail email = new SimpleEmail();
        email.setHostName("mail.fastunit.com");
        email.setAuthentication("support@fastunit.com", "***");//邮件服务器验证:用户名/密码
        email.setCharset("UTF-8");// 必须放在前面,否则乱码
        email.addTo("fastunit.com@hotmail.com");
        email.setFrom("support@fastunit.com", "support");
        email.setSubject("subject中文");
        email.setMsg("msg中文");
        email.send();

    三、带附件的邮件

        MultiPartEmail email = new MultiPartEmail();
        email.setHostName("mail.fastunit.com");
        email.setAuthentication("support@fastunit.com", "***");
        email.setCharset("UTF-8");
        email.addTo("fastunit.com@hotmail.com");
        email.setFrom("support@fastunit.com", "support");
        email.setSubject("subject中文");
        email.setMsg("msg中文");
        
        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath("d:/a.gif");// 本地文件
        // attachment.setURL(new URL("http://xxx/a.gif"));//远程文件
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setDescription("a");
        attachment.setName("a");
        
        email.attach(attachment);
        email.send();

    四、HTML格式邮件

        HtmlEmail email = new HtmlEmail();
        email.setHostName("mail.fastunit.com");
        email.setAuthentication("support@fastunit.com", "***");
        email.setCharset("UTF-8");
        email.addTo("fastunit.com@hotmail.com");
        email.setFrom("support@fastunit.com", "support");
        email.setSubject("subject中文");
        email.setHtmlMsg("<b>msg中文</b>");
        email.send();

    五、其他 

    使用免费邮箱来测试时,有些免费邮箱不提供此服务,无法通过邮件服务器验证。

  • 相关阅读:
    redhat,centos Linux常用命令LS之常用功能
    人生信用卡
    如何让Redhat Linux启动时进入字符终端模式(不进入XWindow)
    OpenJDK和JDK区别
    Linux rpm 命令参数使用详解[介绍和应用]
    linux 的vim命令详解
    centos6.4安装javajdk1.8
    samba服务器 实现Linux与windows 文件共享
    SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换
    linux学习之 Linux下的Eclipse安装
  • 原文地址:https://www.cnblogs.com/dobestself-994395/p/4296305.html
Copyright © 2011-2022 走看看