首页上一页 1 下一页尾页 3 条记录 1/1页
发送Email出现错误
发表在JavaWeb图书答疑
2011-12-05
是否精华
是
否
版块置顶:
是
否
首先我下载了magic winmail服务器并启动,
编写java代码:
String to = "javajobcom@yahoo.cn";
String from = "javajobcom@yahoo.cn";
String sub = "hello";
String message = "hello java email";
String pwd = ""; //这里密码就不发出来了,在运行中密码是对的
System.out.println("==========邮件发送========");
System.out.println("--发送人-->:"+to);
System.out.println("--接收人-->:"+from);
System.out.println("--主题---->:"+sub);
System.out.println("--内容---->:"+message);
//============Internet发送
int n=from.indexOf("@");
int m=from.length();
String mailsever="smtp."+from.substring(n+1,m);
//=======================
//局域网中发送邮件
//String mailsever="localhost";
//建立邮件会话
Properties pro = new Properties();
pro.put("mail.smtp.host",mailsever);
pro.put("mail.smtp.auth", "true");
Session ses = Session.getInstance(pro);
ses.setDebug(true);
//消息对象
MimeMessage msg = new MimeMessage(ses);
//设置发件人
try {
InternetAddress frommail = new InternetAddress(from);
msg.setFrom(frommail);
//收件人
InternetAddress tomail = new InternetAddress(to);;
msg.setRecipient(Message.RecipientType.TO, tomail);
//主题
msg.setSubject(sub);
//内容
msg.setText(message);
//时间
msg.setSentDate(new Date());
//保存更多Bodypart对象
Multipart mul = new MimeMultipart();
BodyPart mdp = new MimeBodyPart();
mdp.setContent(mul,"text/html;Charset=GBK");
mul.addBodyPart(mdp);
msg.setContent(mul);
msg.saveChanges();
Transport sport = ses.getTransport("smtp");
[font color=#FF0000]sport.connect(mailsever, pwd);[/font]
sport.send(msg,msg.getAllRecipients());
sport.close();
out.println("<script language='javascript'>alert('send email success!')</script>");
response.sendRedirect("email/email1.jsp");
当运行到sport.connect(mailsever, pwd);出现异常!
异常内容:"发送邮件产生的错误:535 read error"
QQ:1543150073
编写java代码:
String to = "javajobcom@yahoo.cn";
String from = "javajobcom@yahoo.cn";
String sub = "hello";
String message = "hello java email";
String pwd = ""; //这里密码就不发出来了,在运行中密码是对的
System.out.println("==========邮件发送========");
System.out.println("--发送人-->:"+to);
System.out.println("--接收人-->:"+from);
System.out.println("--主题---->:"+sub);
System.out.println("--内容---->:"+message);
//============Internet发送
int n=from.indexOf("@");
int m=from.length();
String mailsever="smtp."+from.substring(n+1,m);
//=======================
//局域网中发送邮件
//String mailsever="localhost";
//建立邮件会话
Properties pro = new Properties();
pro.put("mail.smtp.host",mailsever);
pro.put("mail.smtp.auth", "true");
Session ses = Session.getInstance(pro);
ses.setDebug(true);
//消息对象
MimeMessage msg = new MimeMessage(ses);
//设置发件人
try {
InternetAddress frommail = new InternetAddress(from);
msg.setFrom(frommail);
//收件人
InternetAddress tomail = new InternetAddress(to);;
msg.setRecipient(Message.RecipientType.TO, tomail);
//主题
msg.setSubject(sub);
//内容
msg.setText(message);
//时间
msg.setSentDate(new Date());
//保存更多Bodypart对象
Multipart mul = new MimeMultipart();
BodyPart mdp = new MimeBodyPart();
mdp.setContent(mul,"text/html;Charset=GBK");
mul.addBodyPart(mdp);
msg.setContent(mul);
msg.saveChanges();
Transport sport = ses.getTransport("smtp");
[font color=#FF0000]sport.connect(mailsever, pwd);[/font]
sport.send(msg,msg.getAllRecipients());
sport.close();
out.println("<script language='javascript'>alert('send email success!')</script>");
response.sendRedirect("email/email1.jsp");
当运行到sport.connect(mailsever, pwd);出现异常!
异常内容:"发送邮件产生的错误:535 read error"
QQ:1543150073