|
一个发送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"); } */ } |
一个发送mail的javabean
.NET相关技术探讨
最新推荐文章于 2025-11-30 10:33:36 发布
博客围绕.NET展开,虽未给出具体内容,但推测涉及.NET相关信息技术知识。.NET是后端开发常用技术,在软件开发等领域有广泛应用。
765

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



