<%@ 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>
内网是自己搭建的邮件服务器么?我以前用过apache的开源邮件服务器james,也是只需要设置props.setProperty("mail.host", "smtp.mymail.com")就可以了,至于smtp.mymail.com是可以配置在邮件服务器里面的,跟ip没关系的欢迎分享,转载请注明来源:夏雨云
评论列表(0条)