我有一个发送的代码:
public class AutoSendMail {
public AutoSendMail() {
}
String host = null;
String username = null;
String password = null;
public void setHost(String host){
this.host = host;
} public void setAccount(String username,String password){
this.username = username;
this.password = password;
}
public void AutoSendMail(String from,String to,String cc,String subject,String content){
Properties props = new Properties();
props.put("mail.smtp.host", "camellia.test.com.cn");
//props.put("mail.smtp.auth", "true");
try{
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(false);
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.addRecipient(Message.RecipientType.CC,new InternetAddress(cc)); message.setSubject(subject);
message.setHeader("Dear All","");
message.setText(content);
message.saveChanges(); Transport transport = mailSession.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception ex){
log4j.error.error("Auto Send Mail Error : " + ex.getMessage());
System.out.println(ex.getMessage());
}
}
public class AutoSendMail {
public AutoSendMail() {
}
String host = null;
String username = null;
String password = null;
public void setHost(String host){
this.host = host;
} public void setAccount(String username,String password){
this.username = username;
this.password = password;
}
public void AutoSendMail(String from,String to,String cc,String subject,String content){
Properties props = new Properties();
props.put("mail.smtp.host", "camellia.test.com.cn");
//props.put("mail.smtp.auth", "true");
try{
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(false);
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.addRecipient(Message.RecipientType.CC,new InternetAddress(cc)); message.setSubject(subject);
message.setHeader("Dear All","");
message.setText(content);
message.saveChanges(); Transport transport = mailSession.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception ex){
log4j.error.error("Auto Send Mail Error : " + ex.getMessage());
System.out.println(ex.getMessage());
}
}
解决方案 »
- 各位、亲 。 来看看吧。
- [讨论]大家做jsp开发 都用什么工具呢?
- 问个小问题,请高手解答!在线等!
- 求java实现服务器指定目录下文件内容检索的实例
- jscript不能用jsp程序片断,那我该怎么实现这样的功能?
- 我原来在软件培训机构学了2年的Java web知识,框架也学了.... 求帮助
- 保存jsp文件时遇到问题,help
- (救急)Weblog6.1如何解决中文问题?
- tomcat 环境jsp调用javabean,bean的位置?请指点
- 奇怪!!奇怪!真是不可理解。哪位大哥帮帮忙。
- 重金求购:网络营销\远程仓储管理模拟系统\国际货贷\条形码编辑
- 烦死了,急死了,请大虾进来看看,100分相送!!
像使用Yahoo来发邮件,其实你就是模拟IE的发送过程。你必须知道邮件服务器的登录Form的接口参数等等。简单来说就是你的程序模拟你在IE中的一切与服务器交换的信息。