java mail 连接邮件服务器

java mail 连接邮件服务器,第1张

不知有帮助没有了

<%@ 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没关系的


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/284385.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-22
下一篇2023-04-22

发表评论

登录后才能评论

评论列表(0条)

    保存