package com.dl.mail;import java.io.UnsupportedEncodingException;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;public class SendMail {
private String fromMail;
private String smtp;
private String userName;
private String password;
//构造方法初始化参数
public SendMail(String fromMail,String smtp,String userName,String password){
this.fromMail=fromMail;
this.smtp=smtp;
this.userName=userName;
this.password=password;
}
public void sendMail(String toMail,String title,String message) throws UnsupportedEncodingException{
Properties props = System.getProperties();
// 设置SMTP邮件服务器:
props.put("mail.smtp.host",smtp);
//props.put("mail.smtp.localhost", smtp);
// SMTP服务器需要验证:
props.put("mail.smtp.auth", "true");
// 传入用户名和口令:
Session session = Session. getDefaultInstance(props,
new PasswordAuthenticator(userName,password));
// 创建新邮件
Message msg = null;
msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(fromMail));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(new String(toMail.getBytes("gb18030"),"gb2312")));
msg.setSubject(new String(title.getBytes("gb18030"),"gb2312"));
msg.setText(new String(message.getBytes("gb18030"),"gb2312"));
msg.setSentDate(new Date());
// 发送:
Transport.send(msg);
System.out.println("邮件发送成功-->"+new Date().toLocaleString());
} catch (AddressException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
}
}
/*public static void main(String[] arge) throws Exception {
SendMail mail = new SendMail("[email protected]","smtp.tsa.cn","[email protected]","zclswj");
String toMail = "[email protected]";
String title = "标题A";
String message = "内容A";
mail.sendMail(toMail, title, message);
} */
}错误代码:javax.mail.MessagingException: 501 domain address required: HELO还请高手指教!!
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;public class SendMail {
private String fromMail;
private String smtp;
private String userName;
private String password;
//构造方法初始化参数
public SendMail(String fromMail,String smtp,String userName,String password){
this.fromMail=fromMail;
this.smtp=smtp;
this.userName=userName;
this.password=password;
}
public void sendMail(String toMail,String title,String message) throws UnsupportedEncodingException{
Properties props = System.getProperties();
// 设置SMTP邮件服务器:
props.put("mail.smtp.host",smtp);
//props.put("mail.smtp.localhost", smtp);
// SMTP服务器需要验证:
props.put("mail.smtp.auth", "true");
// 传入用户名和口令:
Session session = Session. getDefaultInstance(props,
new PasswordAuthenticator(userName,password));
// 创建新邮件
Message msg = null;
msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(fromMail));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(new String(toMail.getBytes("gb18030"),"gb2312")));
msg.setSubject(new String(title.getBytes("gb18030"),"gb2312"));
msg.setText(new String(message.getBytes("gb18030"),"gb2312"));
msg.setSentDate(new Date());
// 发送:
Transport.send(msg);
System.out.println("邮件发送成功-->"+new Date().toLocaleString());
} catch (AddressException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
System.out.println(e);
e.printStackTrace();
}
}
/*public static void main(String[] arge) throws Exception {
SendMail mail = new SendMail("[email protected]","smtp.tsa.cn","[email protected]","zclswj");
String toMail = "[email protected]";
String title = "标题A";
String message = "内容A";
mail.sendMail(toMail, title, message);
} */
}错误代码:javax.mail.MessagingException: 501 domain address required: HELO还请高手指教!!
解决方案 »
- 如何拆分、组合新的字符串?很急!谢谢各位,
- JSP文本读取读入
- 如何用jsp给win系统环境变量赋值
- Javassist动态生成的类
- 我用jspsmart上传图片后,cpu就占用100%,这个问题怎么解决?
- mysql乱码问题!?急
- 连接SQLSERVER出现了问题,在线等!!
- 异常:org.apache.catalina.startup.Catalina javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
- 关于JDOM的应用
- 关于打印的又一新问题(急)!!!
- Derby[javaDB]的问题。在线等待!
- error-page配置为何不起作用
楼主截止到2008-06-18 15:04:10的汇总数据:
发帖数:1
结贴数:0
结贴率: 0.00%
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
IP地址
Properties props = System.getProperties();
// 设置SMTP邮件服务器:
props.put("mail.smtp.host",smtp);
//props.put("mail.smtp.localhost", smtp);
// SMTP服务器需要验证:
props.put("mail.smtp.auth", "true");
// 传入用户名和口令:不要注释掉
props.put("mail.smtp.localhost", "localhost");
是对的!
但是我昨天试就没有成功啊!
郁闷!