Could not connect to SMTP host: smtp.sina.com.cn, port: 25, response: -1 60
javax.mail.MessagingException:CouldnotconnecttoSMTPhost:smtp.sina.com.cn,port:25,resp...
javax.mail.MessagingException: Could not connect to SMTP host: smtp.sina.com.cn, port: 25, response: -1
java写个邮件的发送,总是不出现这个异常
在网上查,说可能是防火墙的问题,关了之后偶尔可以成功几次
但现在都关了也一次都成功不了...
希望有高手指点下
"工具->账户->再选择你自己的账户->属性->服务器->最后,在发送服务器 下面勾选 “我的服务器要求身份验证(V)"
这个说的是哪的选项。。。我不太清楚,麻烦说细点 展开
java写个邮件的发送,总是不出现这个异常
在网上查,说可能是防火墙的问题,关了之后偶尔可以成功几次
但现在都关了也一次都成功不了...
希望有高手指点下
"工具->账户->再选择你自己的账户->属性->服务器->最后,在发送服务器 下面勾选 “我的服务器要求身份验证(V)"
这个说的是哪的选项。。。我不太清楚,麻烦说细点 展开
3个回答
展开全部
功夫不负有心人,最后了解到,除了google的smtp服务器收到请求“smtp”会接受,其他服务器比如qq 163什么的必须要收到“smtp”请求(大写),郁闷呀!
参考资料: http://www.dao-gu.com/web/Could-not-connect-to-SMTP-host.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上说的,加上我这个代码,应该可以帮你找到问题!
<%@ page import="javax.mail.Session"%>
<%@ page import="javax.mail.Transport"%>
<%@ page import="javax.mail.internet.InternetAddress"%>
<%@ page import="javax.mail.internet.MimeMessage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<%
try{
String smtpServer = request.getParameter("txtSmtp");
String emailFrom = request.getParameter("txtFrom");
String userId = request.getParameter("txtId");
String userPwd = request.getParameter("txtPwd");
String emailTo = request.getParameter("txtTo");
String subject = request.getParameter("txtSubject");
String body = request.getParameter("txtBody");
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
javax.mail.Session sess = Session.getDefaultInstance(props,null);
Message msg = new MimeMessage(sess);
msg.setFrom(new InternetAddress(emailFrom));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(emailTo, false));
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate(new Date());
Transport transport = sess.getTransport("smtp");
transport.connect(smtpServer,userId,userPwd);
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
%>
<div align="center">
<p><font color="#FF6600" size="4">Send Success!</font></p><br>
<a href="SendEmail.jsp">Re-Send again!</a></p>
</div>
<%
}catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html>
如果是在类里面写,比这个还简单些!
<%@ page import="javax.mail.Session"%>
<%@ page import="javax.mail.Transport"%>
<%@ page import="javax.mail.internet.InternetAddress"%>
<%@ page import="javax.mail.internet.MimeMessage"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<%
try{
String smtpServer = request.getParameter("txtSmtp");
String emailFrom = request.getParameter("txtFrom");
String userId = request.getParameter("txtId");
String userPwd = request.getParameter("txtPwd");
String emailTo = request.getParameter("txtTo");
String subject = request.getParameter("txtSubject");
String body = request.getParameter("txtBody");
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
javax.mail.Session sess = Session.getDefaultInstance(props,null);
Message msg = new MimeMessage(sess);
msg.setFrom(new InternetAddress(emailFrom));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(emailTo, false));
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate(new Date());
Transport transport = sess.getTransport("smtp");
transport.connect(smtpServer,userId,userPwd);
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
%>
<div align="center">
<p><font color="#FF6600" size="4">Send Success!</font></p><br>
<a href="SendEmail.jsp">Re-Send again!</a></p>
</div>
<%
}catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html>
如果是在类里面写,比这个还简单些!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |