1.添加依赖,
      commons-email  等等 
@Test
public void sendMail() throws EmailException, MalformedURLException, UnsupportedEncodingException {//可以添加发送响应的类
HtmlEmail email = new HtmlEmail();
       //HostName的配置
email.setHostName("smtp.163.com");
       //发送文件的邮箱地址
email.setSSLOnConnect(true);
      //接收文件的邮箱地址
email.addTo("16910735@qq.com", "");
     //发送文件的邮箱及密码
email.setSubject("账号激活");
email.setCharset("UTF-8");
// 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
String content="<html><meta charset=\"utf-8\" />" +
"账号激活地址:<a href='http://localhost:8080/user/xxxxxxxxxxxx'>http://localhost:8080/user/xxxxxxxxxxxx</a>"+
"</html>";
email.setHtmlMsg(new String(content.getBytes(),"UTF-8"));
// set the alternative message;文件的内容
email.setTextMsg("此邮件不需要回复");
// send the email;确认发送
email.send();}
 
                   
                   
                   
                   本文介绍如何利用commons-email库从163邮箱发送包含HTML内容和内嵌图片的邮件。示例代码展示了如何设置邮件服务器、认证信息、收发方地址、邮件主题与内容,并附带了具体的发送方法。
本文介绍如何利用commons-email库从163邮箱发送包含HTML内容和内嵌图片的邮件。示例代码展示了如何设置邮件服务器、认证信息、收发方地址、邮件主题与内容,并附带了具体的发送方法。
           
       
           
                 
                 
                 
                 
                 
                
               
                 
                 
                 
                 
                
               
                 
                 扫一扫
扫一扫
                     
              
             
                   664
					664
					
 被折叠的  条评论
		 为什么被折叠?
被折叠的  条评论
		 为什么被折叠?
		 
		  到【灌水乐园】发言
到【灌水乐园】发言                                
		 
		 
    
   
    
   
             
            


 
            