日期:2014-05-18 浏览次数:20749 次
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
public class Mail {
public void sendEmail(String add){
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.sina.com");//sina的smtp服务器,用于发送邮件的协议
email.setAuthentication("hhr6523944@sina.cn", "xxxx");//登录smtp服务器的验证
email.setCharset("utf-8");//编码的方式
try {
email.addTo(add);//收方的地址
email.setFrom("hhr6523944@sina.cn");//发方的地址
email.setSubject("xx网");//邮件主题
email.setMsg("亲爱的"+add+"用户"+"感谢您注册xx网");//邮件内容
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
}
public void sendEmail(String add,String goods){
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.sina.com");
email.setAuthentication("hhr6523944@sina.cn", "xxx");
email.setCharset("utf-8");
try {
email.addTo(add);
email.setFrom("hhr6523944@sina.cn");
email.setSubject("xx网");
email.setMsg("亲爱的"+add+"用户"+"您购买了xx网的"+goods+"我们将及时为您发货");
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
}
}
public class Send {用第二个类去调用第一个类的方法时出现了问题
public static void main(String[] args){
Mail a =new Mail();
String add = "6523944@qq.com";
a.sendEmail(add);
}
}