从jsp发送邮件时如何解决异常 [英] how can resolve exception while send mail from jsp
本文介绍了从jsp发送邮件时如何解决异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用此编码使用我的hotmail帐户从jsp程序发送邮件..
i tried this coding to send mail from jsp program using my hotmail account..
<%@page import ="java.sql.*" %>
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%
String host ="smtp.live.com";
String from ="my hotmail email id@hotmail.com";
String to ="receiver mail id.com";
String pass="my hotmail password ";
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.user","myid@hotmail.com");
props.put("mail.smtp.password","mypassword");
Session msession = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(msession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
Transport tr = msession.getTransport("smtp");
tr.connect(host, from, pass);
// Send messa
tr.send(message);
// Send message
%>
但我得到如下所示的错误
but i got error as shown below
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.io.IOException: Server is not trusted: smtp.live.com
root cause
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.io.IOException: Server is not trusted: smtp.live.com
root cause
java.io.IOException: Server is not trusted: smtp.live.com
note The full stack traces of the exception and its root causes are available in the GlassFish v3 logs.
我该如何解决此错误..
how can i resolve this error..
推荐答案
对不起,但我建议不要使用hotmail帐户发送邮件
使用yahoo或Google
阅读下面的博客,并以此来完善您的代码
http://bytes.com/topic/java/answers/16139-send- mails-via-jsp-servlets [ ^ ]
Sorry but I would suggest to not use hotmail account for sending mail
use yahoo or Google
read below blog and compair your code with this
http://bytes.com/topic/java/answers/16139-send-mails-via-jsp-servlets[^]
这篇关于从jsp发送邮件时如何解决异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文