用javamail发邮件问题,

boat2002w 2003-08-21 03:00:40
javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Unknown SMTP host: smtp.jspinsider.com; nested exception is: java.net.UnknownHostException: smtp.jspinsider.com
这是什么错误?我用了新浪和eyou都不行。



还有从网上抄了这么一段代码,为什么不报错,也收不到信?
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.util.*,javax.mail.*,javax.mail.internet.*,javax.activation.*,javax.swing.*,java.awt.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<%//标题
String message_subject="title";
//正文
String message_body="邮件正文内容!";

//JavaMail Session对象
Session psession;
//JavaMail Message对象
Message mesg;
Properties props=new Properties();
props.put("mail.smtp.host","smtp.sina.com.cn");//这里必须正确填入你的smtp(我这里添的是新浪的smtp)

psession=Session.getDefaultInstance(props,null);
psession.setDebug(true);

try
{
//创建一个邮件
mesg=new MimeMessage(psession);
//FROM地址
mesg.setFrom(new InternetAddress("wuwei0199_cn@sina.com"));
//TO地址
InternetAddress toAddress=new InternetAddress("wuwei0199_cn@sina.com");
mesg.addRecipient(Message.RecipientType.TO,toAddress);
//标题
mesg.setSubject(message_subject);
//正文
mesg.setText(message_body);

Transport transport = psession.getTransport("smtp");
transport.connect("smtp.sina.com.cn", "wuwei0199_cn","******");//这里添一个你自己的邮件用户名和密码(假如为xxx.sina.com,密码为1234)
//最后发送邮件
transport.send(mesg);
}
catch(MessagingException ex)
{
while((ex=(MessagingException)ex.getNextException())!=null)
{
ex.printStackTrace();
}
}
%>
<body>

</body>
</html>
...全文
109 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
boat2002w 2003-08-25
  • 打赏
  • 举报
回复
Come on!
boat2002w 2003-08-22
  • 打赏
  • 举报
回复
lijunisbug
你给我发到我的邮箱里好了,
wuwei0199_cn@eyou.com
如果试验成功一定给分
boat2002w 2003-08-22
  • 打赏
  • 举报
回复
高手帮解决以下嘛!!!
lijunisbug 2003-08-21
  • 打赏
  • 举报
回复
小菜一叠!~~~~
给了分,我就给你完整代码!~~~~~~~

boat2002w 2003-08-21
  • 打赏
  • 举报
回复
leojeff(★爱上你等于爱上一种艺术★) :
请问在jsp 页面中应该如何引入这个bean?
我觉得就是认证的问题,在jsp中怎样加入认证?
谢谢各位
boat2002w 2003-08-21
  • 打赏
  • 举报
回复
hesi726(hesi)
你帮我仔细写一下代码可以吗?按照你上面写的报了好多错误,小地方我还能改,有的错误我就看不出来了。比如
D:\tomcat\work\Standalone\localhost\_\test\test5_jsp.java:73: illegal start of expression
transport.connect("smtp.sina.com.cn");, "wuwei0199_cn","1******");//当然我把密码改了
还有你好多变量都没有定义
leojeff 2003-08-21
  • 打赏
  • 举报
回复
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.activation.FileDataSource;

public class SendMail {
private String msgText = null;
private String subject = null;
private String smtpHost = null;
private String from = null;
private String to = null;
public void setMsgText(String msgText) {
this.msgText = msgText;
}

public void setSubject(String subject) {
this.subject = subject;
}

public void setSmtpHost(String smtpHost) {
this.smtpHost = smtpHost;
}

public void setFrom(String from) {
this.from = from;
}

public void setTo(String to) {
this.to = to;
}

public SendMail() {}

public SendMail(String msgText,
String subject,
String smtpHost,
String from,
String to) {
this.msgText = msgText;
this.subject = subject;
this.smtpHost = smtpHost;
this.from = from;
this.to = to;
}

public void sendnow() throws Exception {
try {
Properties props = new Properties();
props.setProperty("mail.smtp.host", smtpHost);
Session session = Session.getDefaultInstance(props, null);

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] address = {
new InternetAddress(to)};
message.setRecipients(Message.RecipientType.TO, address);

message.setSubject(subject);
message.setSentDate(new Date());
message.setText(msgText);

Transport.send(message);
}
catch (Exception ex) {
throw new Exception("SendMail.sendnow" + ex.getMessage());

}
}
}
hesi726 2003-08-21
  • 打赏
  • 举报
回复
看异常信息,好像是不能找到主机哦!
先获得主机的IP地址吧!
hesi726 2003-08-21
  • 打赏
  • 举报
回复
试试下面的代码!
如果不行,报什么异常???
Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.sina.com.cn");
props.put("mail.smtp.auth","true");
Transport transport;

Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
Message msg = new MimeMessage(session);
InternetAddress toAddress=new InternetAddress("wuwei0199_cn@sina.com");
mesg.addRecipient(Message.RecipientType.TO,toAddress);
mesg.setFrom(new InternetAddress("wuwei0199_cn@sina.com"));
msg.setHeader("X-Mailer", mailer);
msg.setSentDate(new Date());
mesg.setSubject(message_subject);
mesg.setText(message_body);

transport = session.getTransport("smtp");
transport.connect("smtp.sina.com.cn");, "wuwei0199_cn","******");//
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();




boat2002w 2003-08-21
  • 打赏
  • 举报
回复
高手帮忙呀
boat2002w 2003-08-21
  • 打赏
  • 举报
回复
高手帮忙呀
boat2002w 2003-08-21
  • 打赏
  • 举报
回复
i has looked for it all noon,but have little understanding about it.
So please have a look my question,and help me solve the question.
Thanks a lot!
takecare 2003-08-21
  • 打赏
  • 举报
回复
please search it in this forum

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧