javaMail发送邮件实例,支持附件和多人邮件的发送 (五)
.util.List;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MyAuthenticator extends Authenticator{
String userName=null;
String password=null;
public MyAuthenticator(){
}
public MyAuthenticator(String username, String password) {
this.userName = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userName, password);
}
public static void main(String[] args){
//这个类主要是设置邮件
MailSenderInfoBean mailInfo = new MailSenderInfoBean();
mailInfo.setMailServerHost("smtp.sina.com");
mailInfo.setMailServerPort("25");
mailInfo.setValidate(true);
mailInfo.setUserName("wangyou_huai1989@sina.com");
mailInfo.setPassword("**********");//您的邮箱密码
mailInfo.setFromAddress("wangyou_huai1989@sina.com");
List address = new ArrayList();
address.add("850509766@qq.com");
address.add("814884653@qq.com");
address.add("578251346@qq.com");
mailInfo.setToAddress(address);
mailInfo.setSubject("邮件测试案例已经发到邮箱,请查收");
mailInfo.setContent("邮件测试案例已经发到邮箱,请查收,项目中用到了两个jar包,用的时候一并导入即可");
List attachFileNames = new ArrayList();
//此处是你要得到的上传附件的文件路径
attachFileNames.add("C:\\Users\\Administrator\\Desktop\\javaMail.rar");
mailInfo.setAttachFileNames(attachFileNames);
//这个类主要来发送邮件
SimpleMailSender sms = new SimpleMailSender();
//sms.sendTextMail(mailInfo);//发送文体格式
try {
//采取html格式发送
sms.sendHtmlMail(mailInfo);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//发送html格式
}
}
package com.util.mail;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MyAuthenticator extends Authenticator{
String userName=null;
String password=null;
public MyAuthenticator(){
}
public MyAuthenticator(String username, String password) {
this.userName = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userName, password);
}
public static void main(String[] args){
//这个类主要是设置邮件
MailSenderInfoBean mailInfo = new MailSenderInfoBean();
mailInfo.setMailServerHost("smtp.sina.com");
mailInfo.setMailServerPort("25");
mailInfo.setValidate(true);
mailInfo.setUserName("wangyou_huai1989@sina.com");
mailInfo.setPassword("**********");//您的邮箱密码
mailInfo.setFromAddress("wangyou_huai1989@sina.com");
List
address = new ArrayList();
address.add("850509766@qq.com");
address.add("814884653@qq.com");
address.add("578251346@qq.com");
mailInfo.setToAddress(address);
mailInfo.setSubject("邮件测试案例已经发到邮箱,请查收");
mailInfo.setContent("邮件测试案例已经发到邮箱,请查收,项目中用到了两个jar包,用的时候一并导入即可");
List attachFileNames = new ArrayList();
//此处是你要得到的上传附件的文件路径
attachFileNames.add("C:\\Users\\Administrator\\Desktop\\javaMail.rar");
mailInfo.setAttachFileNames(attachFileNames);
//这个类主要来发送邮件
SimpleMailSender sms = new SimpleMailSender();
//sms.sendTextMail(mailInfo);//发送文体格式
try {
//采取html格式发送