Q
qiqijsp
Unregistered / Unconfirmed
GUEST, unregistred user!
以下是发送电子邮件的源码,在这之前我已经从sun的网站下载了JavaMail文件和JAF文件,把里面的jar文件全放在了Classpath下
可是却产生了例外:
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
我怀疑是这句 props.put("mail.smtp.host", "smtp.jspinsider.com");
产生了问题,可是不知道怎么改
在API文档中也没找到它的方法。
很急,希望高手们帮我解决这个问题,这里先谢了。
<%@ page import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*" %>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</hEAD>
<BODY>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.jspinsider.com");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("text"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>
可是却产生了例外:
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
我怀疑是这句 props.put("mail.smtp.host", "smtp.jspinsider.com");
产生了问题,可是不知道怎么改
在API文档中也没找到它的方法。
很急,希望高手们帮我解决这个问题,这里先谢了。
<%@ page import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*" %>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</hEAD>
<BODY>
<%
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.jspinsider.com");
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("text"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>