Unknown SMTP host的问题

lanfengjiyue 2003-04-08 11:40:33
我以前在实习公司做过邮件发送程序,当时可以使用,现在我在学校里使用抛出如下异常:
javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: Unknown SMTP host: smtp.eyou.com; nested exception is: java.net.UnknownHostException: smtp.eyou.com

这是怎么回事啊?程序我一点变动都没有。
而且我在jsp中使用javamail发送程序(网上下载),也是抛同样的异常。
...全文
1384 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanfengjiyue 2003-04-08
  • 打赏
  • 举报
回复
谢谢,我知道了,我们学校把25端口给封了!
takecare 2003-04-08
  • 打赏
  • 举报
回复
telnet yourstmphost 25
gxj0637 2003-04-08
  • 打赏
  • 举报
回复
端口已被封掉,要开ftp权限
lanfengjiyue 2003-04-08
  • 打赏
  • 举报
回复
如何确认?
jcq 2003-04-08
  • 打赏
  • 举报
回复
你确定你的邮件服务器能够访问的到是吗
lanfengjiyue 2003-04-08
  • 打赏
  • 举报
回复
我自己写的程序:

public class test {
public static void main(String[] args) {
String host = "smtp.pubinfo.com.cn";
String from = "chjin@pubinfo.com.cn";
String to = "chjin@pubinfo.com.cn";
String username = "****";
String password = "****";
String subject = "中文测试Send Mail Testing";
String content = "中文测试";

MailSend mailsend = new MailSend(host,from,to,username,password,subject,content);
mailsend.msgSend();
System.exit(0);
}

/////////////////////////////////////////////////////////
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
import javax.activation.*;

public class MailSend{
String host;
String from;
String to;
String username;
String password;
String subject;
String content;

public MailSend(String host,String from,String to,String username,
String password,String subject,String content){
this.host = host;
this.from = host;
this.to = to;
this.username = username;
this.password = password;
this.subject = subject;
this.content = content;
}

public void msgSend(){
try{
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
//Setup mail Auth
Authenticator auth = new MyAuthenticator(username,password);
// Get session
Session session = Session.getDefaultInstance(props, auth);

// Define message
MimeMessage message = new MimeMessage(session);

// Set the from address
message.setFrom(new InternetAddress(from));

// Set the to address
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
// Set the subject
message.setSubject(subject);
// Set the content
message.setText(content);
// Send message
Transport.send(message);

System.out.println("\nMail was sent successfully.");
}catch(Exception theException) {
System.out.println(theException);
}

}
}

////////////////////////////////////////
import javax.mail.*;
import java.util.*;

public class MyAuthenticator extends Authenticator {
String username, password;

public MyAuthenticator(String username,String password)
{
this.username = username;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}

}


takecare 2003-04-08
  • 打赏
  • 举报
回复
ping能通吗?是不是网络的问题。
jcq 2003-04-08
  • 打赏
  • 举报
回复
props.put("mail.smtp.host", "smtp.eyou.com");
这里的问题吧,你应该使用参数来设置正确的smtp服务器的
lanfengjiyue 2003-04-08
  • 打赏
  • 举报
回复
jsp 的程序:


<%@ page
import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"
%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
String from=request.getParameter("from");
String to=request.getParameter("to");

String subject=new String(request.getParameter("subject").getBytes("ISO8859-1"),"GB2312");

String text=new String(request.getParameter("neirong").getBytes("ISO8859-1"),"GB2312");

try{
Properties props = System.getProperties();
Session sendMailSession;
Store store;
Transport transport;

props.put("mail.smtp.host", "smtp.eyou.com");
sendMailSession = Session.getInstance(props, null);



Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(from));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
newMessage.setSubject(subject);
newMessage.setText(text);
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>

81,092

社区成员

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

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