标签:mime send import 标题 dmi file enc block ted
这里使用的是commons-email-1.3.2.jar进行的开发,自认为这是简单的邮件发送。 package com.yt.base.common; import java.io.UnsupportedEncodingException; import javax.mail.internet.MimeUtility; import org.apache.commons.mail.DefaultAuthenticator; import org.apache.commons.mail.EmailAttachment; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.HtmlEmail; public class email { public static void main(String[] args) { // TODO Auto-generated method stub try { HtmlEmail textemail = new HtmlEmail(); textemail.setHostName("smtp.163.com");//smtp邮箱服务器的地址 textemail.setSmtpPort(25);//smtp的端口号 textemail.setAuthenticator(new DefaultAuthenticator("xxx@163.com", "soiladmin"));//发送放的用户名和密码 textemail.setSSLOnConnect(false); textemail.setFrom("xxx@163.com");//发送人 textemail.setSubject("标题");//发送标题 String info = "aaaaaaaaaaaa"; textemail.setHtmlMsg(info);//发送邮箱内容 textemail.addTo("2xx@qq.com");//给什么人(用户)发送的邮箱地址 //email附件发送开始 EmailAttachment attach = new EmailAttachment(); String fileN="D:\\msj.dox"; attach.setPath(fileN); attach.setDisposition(EmailAttachment.ATTACHMENT); try { attach.setName(MimeUtility.encodeText(fileN)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } textemail.attach(attach); //email附件发送结束 String aa= textemail.send(); } catch (EmailException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:mime send import 标题 dmi file enc block ted
原文地址:https://www.cnblogs.com/seeyou1993/p/11473801.html