一个发送mail的javabean

.NET相关技术探讨
博客围绕.NET展开,虽未给出具体内容,但推测涉及.NET相关信息技术知识。.NET是后端开发常用技术,在软件开发等领域有广泛应用。
一个发送mail的javabean

发布日期:2003-1-9  发 布 者:51jsp.net  
/*
*Author:tyfun
*DateTime:2003.01.09
*Package:com.westarsoft.function
*/

packagecom.westarsoft.function;

importjava.util.*;
importjava.io.*;
importjavax.mail.*;
importjavax.mail.internet.*;
importjavax.activation.*;

publicclassSendMail{
privateStringSMTPServer=newString();
privateStringfrom=newString();
privateStringsubject=newString();
privateStringcontent=newString();
privateStringuser=newString();
privateStringpassword=newString();
publicStringgetSMTPServer(){
returnSMTPServer;
}
publicvoidsetSMTPServer(StringSMTPServer){
this.SMTPServer=SMTPServer;
}
publicStringgetFrom(){
returnfrom;
}
publicvoidsetFrom(Stringfrom){
this.from=from;
}
publicStringgetSubject(){
returnsubject;
}
publicvoidsetSubject(Stringsubject){
this.subject=subject;
}
publicStringgetContent(){
returncontent;
}
publicvoidsetContent(Stringcontent){
this.content=content;
}
publicStringgetUser(){
returnuser;
}
publicvoidsetUser(Stringuser){
this.user=user;
}
publicStringgetPassword(){
returnpassword;
}
publicvoidsetPassword(Stringpassword){
this.password=password;
}

publicvoidsendMailTo(Stringto){
try{
Propertiesprops=newProperties();
SessionsendMailSession;
Storestore;
Transporttransport;

sendMailSession=Session.getInstance(props,null);
props.put("mail.smtp.host",SMTPServer);
MimeMessagenewMessage=newMimeMessage(sendMailSession);
newMessage.setFrom(newInternetAddress(from));
newMessage.setSubject(subject);
newMessage.setSentDate(newDate());
newMessage.setText(content);

StringTokenizertoken=newStringTokenizer(to,",");
InternetAddress[]addrArr=newInternetAddress[token.countTokens()];
inti=0;
while(token.hasMoreTokens()){
addrArr[i]=newInternetAddress(token.nextToken().toString());
i++;
}

transport=sendMailSession.getTransport("smtp");
transport.connect(SMTPServer,user,password);
newMessage.setRecipients(Message.RecipientType.TO,addrArr);
transport.send(newMessage);
}
catch(Exceptione){
System.out.println(e);
}
}

/*
publicstaticvoidmain(String[]args){
SendMailmail=newSendMail();
mail.setSMTPServer("200.1.1.157");
mail.setUser("lint");
mail.setPassword("30320");
mail.setFrom("lint@westar.com");
mail.setSubject("测试");
mail.setContent("test");
mail.sendMailTo("lint@westar.com,zouy@westar.com,zhangp@westar.com");
}
*/
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值