WEB开发者-分享WEB开发知识,让开发变得更简单!

jsp邮件发送详细解析

要运用jsp编程来实现邮件发送,其实并不是一件很难得事情,但对于一些初学者来说就有点难度了,下面WEB开发者小编就为大家举例介绍下jsp邮件发送是怎样的,仅供参考!

MailExample.jsp
String host = "yourmailhost";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;

// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");

Session mailSession = Session.getDefaultInstance(props, null);

// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
mailSession.setDebug(sessionDebug);

// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(mailSession);

msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.
Transport.send(msg);

out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");

%>

学习了以上WEB开发者小编为大家整理的jsp邮件发送内容后,是不是为你解决掉了燃眉之急呢!更多好文章尽在www.webkfz.com等着你。

本文链接:https://www.webkfz.com/WEBkF/JSP/70935.html

版权声明:站内所有文章皆来自网络转载,只供分享作用,不代表本站的观点!

发表评论 共有 0 条评论)

联系客服
网站客服 业务合作 QQ
1244305267
公众号
公众号
公众号
返回顶部