javax.mail发送邮件jsp页面
2016-05-01 00:56
357 查看
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.util.*"%> <%@page import="javax.mail.*"%> <%@page import="javax.mail.internet.*"%> <%@page import="javax.activation.*"%> <% /* sina.com: POP3服务器地址:pop3.sina.com.cn(端口:110) SMTP服务器地址:smtp.sina.com.cn(端口:25) 163.com: POP3服务器地址:pop.163.com(端口:110) SMTP服务器地址:smtp.163.com(端口:25) */ String recipient="000@qq.com"; String sender="aaa@sina.com"; String subject="hello"; String text="hello, this is my first jsp mail!"; String host="smtp.sina.com.cn"; String username="aaa@sina.com"; String password="000"; Properties props=new Properties(); props.put("mail.smtp.host",host); props.put("mail.smtp.port","25"); props.put("mail.smtp.auth","true"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); Session mailsession=Session.getDefaultInstance(props); boolean sessionDebug=false; mailsession.setDebug(sessionDebug); MimeMessage message=new MimeMessage(mailsession); message.setFrom(new InternetAddress(sender)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); message.setSubject(subject, "UTF-8"); message.setText(text); message.saveChanges(); Transport transport=mailsession.getTransport("smtp"); transport.connect(host, username, password); transport.sendMessage(message, message.getAllRecipients()); transport.close(); %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>sendmail</title> </head> <body> <h1>邮件已经发送!</h1> </body> </html>
相关文章推荐
- Java多线程编程(二)操作状态与常用方法
- eclipse安装和maven的配置(windows)
- JAVA 泛型
- java.io.FileNotFoundException: class path resource [bean/test/User.hbm.xml] cannot be opened because it does not exist
- Java练习题
- Java编译器分析
- Spring JdbcTemplate方法详解
- Java泛型
- (Spring加载xml时)org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
- readLine方法的简单练习,回答2016-04-27 的帖子的问题
- Java基础串理
- 学习Spring(九) -- Spring使用AOP
- 对象数组、集合、链表(java基础知识十五)
- springmvc请求url始终404错误
- spring boot 集成springmvc视图技术
- eclipse中的server location灰色如何修改?
- java 建造者模式
- 给定两个字符串,请编写程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。这里规定大小写为不同字符,且考虑字符串重点空格。 给定一个string stringA和一个string stri
- Java中交集、并集、差集的实现
- Java多线程编程(一)