|
|
|
|
问题类别:空间问题 (点击数:23545)
问题:JAVAMAIL 例子
|
|
http://www.now.cn/support/host/javamail.net
JAVA Mail 发邮件的例子
|
javamail.jsp 内容如下 <%@page contentType="text/html;charset=gb2312"%> <%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %> <html> <head> <title>JavaMail 电子邮件发送系统</title> </head> <body>
<% // 以下变量为用户根据自己的情况设置 String smtphost = "smtp.now.net.cn"; // 发送邮件服务器 String user = "yauboo"; // 邮件服务器登录用户名 String password = "xxx"; // 邮件服务器登录密码 String from = "yauboo@now.net.cn"; // 发送人邮件地址 String to = "yauboo@now.net.cn"; // 接受人邮件地址 String subject = "Java Mail Subject!"; // 邮件标题 String body = "Java Mail Body!"; // 邮件内容
// 以下为发送程序,用户无需改动 try { Properties props = new Properties(); props.put("mail.smtp.host", smtphost); props.put("mail.smtp.auth","true"); Session ssn = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(ssn);
InternetAddress fromAddress = new InternetAddress(from); message.setFrom(fromAddress); InternetAddress toAddress = new InternetAddress(to); message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject); message.setText(body);
Transport transport = ssn.getTransport("smtp"); transport.connect(smtphost, user, password); transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO)); //transport.send(message); transport.close(); %><p>你的邮件已发送,请返回。</p><% } catch(Exception m) { out.println(m.toString()); }%> </BODY> </HTML>
| |
|
|