java学习之路之邮件相关
2016-05-04 23:41
555 查看
smtp 发送邮件 25端口
pop3接受邮件 110端口
============手动发送邮件==============================
D:\Documents and Settings\park>telnet smtp.sina.cn 25
ehlo park
auth login
aXRoZWltYV9wYXJrQHNpbmEuY24=
cXExMjMzMjE=
mail from:itheima_park@sina.cn
rcpt to:itheima_park@sohu.com
Data
from:itheima_park@sina.cn
to:itheima_park@sohu.com
subject: 测试邮件
xxx 自作主张
.
quit
=============Base64编码===============================
public class Base64 {
public static void main(String[] args) throws Exception {
System.out.print(“请输入用户名:”);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String userName = in.readLine();
System.out.print(“请输入密码:”);
String password = in.readLine();
BASE64Encoder encoder = new BASE64Encoder();
System.out.println(“编码后的用户名为:”
+ encoder.encode(userName.getBytes()));
System.out.println(“编码后的密码为:”
+ encoder.encode(password.getBytes()));
}
}
==============JavaMail发送简单邮件-=====================
// prop.setProperty(“mail.smtp.auth”, “true”);
prop.setProperty(“mail.debug”, “true”);
Session session = Session.getInstance(prop);
=========================================================
public static void main(String[] args) throws MessagingException {
Properties prop = new Properties();
prop.setProperty(“mail.transport.protocol”, “smtp”);
prop.setProperty(“mail.smtp.host”, “smtp.sina.cn”);
prop.setProperty(“mail.smtp.auth”, “true”);
prop.setProperty(“mail.debug”, “true”);
pop3接受邮件 110端口
============手动发送邮件==============================
D:\Documents and Settings\park>telnet smtp.sina.cn 25
ehlo park
auth login
aXRoZWltYV9wYXJrQHNpbmEuY24=
cXExMjMzMjE=
mail from:itheima_park@sina.cn
rcpt to:itheima_park@sohu.com
Data
from:itheima_park@sina.cn
to:itheima_park@sohu.com
subject: 测试邮件
xxx 自作主张
.
quit
=============Base64编码===============================
public class Base64 {
public static void main(String[] args) throws Exception {
System.out.print(“请输入用户名:”);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String userName = in.readLine();
System.out.print(“请输入密码:”);
String password = in.readLine();
BASE64Encoder encoder = new BASE64Encoder();
System.out.println(“编码后的用户名为:”
+ encoder.encode(userName.getBytes()));
System.out.println(“编码后的密码为:”
+ encoder.encode(password.getBytes()));
}
}
==============JavaMail发送简单邮件-=====================
@Test public void test1() throws Exception, MessagingException{ Properties prop = new Properties(); prop.setProperty("mail.transport.protocol", "smtp"); prop.setProperty("mail.smtp.host", "localhost");
// prop.setProperty(“mail.smtp.auth”, “true”);
prop.setProperty(“mail.debug”, “true”);
Session session = Session.getInstance(prop);
Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("aa@park.cn")); msg.setRecipient(RecipientType.TO, new InternetAddress("bb@park.cn")); msg.setSubject("来自javaMail的测试邮件!"); msg.setText("来自javaMail的正文内容。。"); Transport tran = session.getTransport(); tran.connect("aa", "123"); tran.send(msg, msg.getAllRecipients()); }
=========================================================
public static void main(String[] args) throws MessagingException {
Properties prop = new Properties();
prop.setProperty(“mail.transport.protocol”, “smtp”);
prop.setProperty(“mail.smtp.host”, “smtp.sina.cn”);
prop.setProperty(“mail.smtp.auth”, “true”);
prop.setProperty(“mail.debug”, “true”);
Session session = Session.getInstance(prop); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("itheima_park@sina.cn")); msg.setRecipient(RecipientType.TO, new InternetAddress("itheima_park@sohu.com")); msg.setSubject("这是我写的标题XXXXXXXXXX"); msg.setText("这是邮件的正文"); Transport tran = session.getTransport(); tran.connect("itheima_park", "qq123321"); tran.sendMessage(msg,msg.getAllRecipients()); }
相关文章推荐
- java 处理CSV(分号里面有逗号)
- [Java] 作业5 (数组)
- java 正则表达式去除标点符号
- Java实现二叉树后序非递归遍历(好理解)
- Spring Mvc那点事---(2)Maven环境搭建
- Java学习笔记1
- Java对象的拷贝
- Spring bean的五种范围域
- 33.IntelliJ IDEA 的 Java 热部署插件 JRebel 安装及使用
- java中静态方法中为什么不能使用this、super和直接调用非静态方法
- [javaSE] 集合框架(共性方法)
- java是值传递还是引用传递。
- 25.Maven 的单模块 / 多模块之 Spring MVC + Spring + Spring Data JPA 项目(基于 IntelliJ IDEA) - IntelliJ IDEA 使用教程
- 24.Maven 的单模块 / 多模块之 Spring MVC + Spring + Mybatis 项目讲解
- 关于javaWeb的Filter过滤器
- Java-Fork/Join的简单例子(入门)
- KMP_java实现
- java将xml转成对象是如此轻松-Unmarshaller
- 第一章 JAVA入门(JDK目录简介)
- 22.Eclipse 的 Java Web 项目环境搭建 - IntelliJ IDEA 使用教程