【发布时间】:2011-07-07 20:10:34
【问题描述】:
我正在努力寻找可用于使用 JSP 发送电子邮件的代码。
我有一个 html 表单来收集消息的文本正文,然后代码应该包含其余信息,以减少用户在向团队发送通知时的工作...... .
JSP代码如下,一直收到错误信息说Session不能解析为类型,Message不能解析为类型,MimeMessage不能解析为类型等等......
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
// SMTP Authentication settings
String host = "smtp.e-tools.com.ve";
String user = "info@e-tools.com.ve";
String pass = "password";
// E-Mail settings
String to = "shee_mass@hotmail.com";
String from = "info@e-tools.com.ve";
String subject = "E-tools Notification - New Document/Comment to see";
String mesg = request.getParameter("smsInput");
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
// Create message to send
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);
// Send message
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, user);
transport.sendMessage(msg, msg.getAllRecipients());
transport.close();
%>
【问题讨论】:
标签: java jsp tomcat jakarta-mail