Apache common mail使用

1:jar包
2:设置你自己的授权码,去你发件邮箱,设置授权码,不会的百度。
3: 代码
多种模式发送邮件,举个例子如下。

public static void main(String[] args) throws Exception{
    // Create the email message
    HtmlEmail email = new HtmlEmail();
    email.setHostName("smtp.163.com");

    email.setAuthentication("[email protected]","*************");

    email.addTo("[email protected]", "Json");
    email.setFrom("[email protected]", "json");

    email.setSubject("Test email with inline image");

    // embed the image and get the content id
    URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
    String cid = email.embed(url, "Apache logo");

    // set the html message
    email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");

    // set the alternative message
    email.setTextMsg("Your email client does not support HTML messages");

    // send the email
    email.send();
  }

猜你喜欢

转载自blog.csdn.net/weixin_39781526/article/details/88819476