主程序:
package Model;
public class SendMailToSomeone {
public static void main(String []args){
SendMailToSomeone smts=new SendMailToSomeone();
smts.send("aa", "hello", "hanshunping@tsinghua.org.cn",
"pinghan2005@sohu.com", "xxx", "smtp.sohu.com");
}
/**
* 发送电子邮件到指定的信箱
* @param title 邮件标题
* @param mailbody 邮件内容【一个网页,表格ok】
* @param sendTo 发送给谁 hanshunping@tsinghua.org.cn
* @param from 从哪些发送 admin@sohu.com
* @param passwd 密码 123456
* @param sendStmp 发送邮件的smtp smtp.sohu.com [smtp.163.com] [smtp.sina.com]
*/
public void send(String title,String mailbody,String sendTo,String from,String passwd,String sendStmp){
//指明让那个smtp转发(搜狐)
MysendMail themail = new MysendMail(sendStmp);
//校验身份
themail.setNeedAuth(true);
//邮件标题
if(themail.setSubject(title) == false) return;
//将要发送的 内容放入邮件体
if(themail.setBody(mailbody) == false) return;
//发送到哪里
if(themail.setTo(sendTo) == false) return;
//谁发送的
if(themail.setFrom(from) == false) return;
//
if(themail.addFileAffix("e:\\butterfly.gif") == false) return;
//

本文介绍了一个使用Java实现的发送邮件至指定邮箱的功能,包括设置邮件标题、正文、接收者、发送者等参数,并通过MIME邮件对象进行邮件内容的构建和发送。
3636

被折叠的 条评论
为什么被折叠?



