jsp邮件发送详细解析

来源:爱站网时间:2020-09-08编辑:网友分享
要运用jsp编程来实现邮件发送,其实并不是一件很难得事情,但对于一些初学者来说就有点难度了,下面爱站技术频道小编就为大家举例介绍下jsp邮件发送是怎样的,仅供参考!

要运用jsp编程来实现邮件发送,其实并不是一件很难得事情,但对于一些初学者来说就有点难度了,下面爱站技术频道小编就为大家举例介绍下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 + ".");

%>

学习了以上爱站技术频道小编为大家整理的jsp邮件发送内容后,是不是为你解决掉了燃眉之急呢!更多好文章尽在js.aizhan.com等着你。

上一篇:如何在JSP中处理表单数据

下一篇:Java开发图形用户界面的操作讲解

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载