Java实现邮件代理发送
使用java实现邮件发送 首先需要添加jar文件
mailapi.jar
stmp.jar 1 import java.util.Properties; import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; /**
* 邮件发送代理线程
* @author helingfeng
*
*/
public class EmailAgent implements Runnable{ private String username;
private String title;
private String content; public EmailAgent(){
//
}
public EmailAgent(String email,String title,String content){
this.username = email;
this.title = title;
this.content = content;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
}
public void run() {
Properties props = new Properties();
//配置协议
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol","smtp"); //创建会话
Session session = Session.getInstance(props);
session.setDebug(true); Message message = null;
Transport transport = null; try {
//创建信息对象
message = new MimeMessage(session);
message.setSubject(title);
message.setText(content);
//参数(用户名)
message.setFrom(new InternetAddress("857190327@qq.com"));
//创建传输对象
transport = session.getTransport();
//参数 (STMP服务器、端口、用户名、密码)
transport.connect("smtp.qq.com", 587, "857190327@qq.com", "密码");
transport.sendMessage(message, new Address[]{new InternetAddress(username)});
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}finally{
try{
if(transport.isConnected()){
transport.close();
transport = null;
}
}catch(MessagingException e1){
e1.printStackTrace();
}
}
}
}
Java实现邮件代理发送的更多相关文章
- Java 实现邮件的发送
Java 实现邮件的发送 开发邮箱发送功能必须看邮箱方面的资料 改一些东西 (我的是qq 邮箱哟 开通 POP3 ...
- JAVA Mail邮件实现发送
package com.test;import java.util.Date;import java.util.Properties;import javax.mail.Message;import ...
- java实现邮件定时发送
最近做项目时客户提出了一个需求:系统定时发送E-mail到其客户,达到通知的效果.先将实例分享给大家,如果确实有一些帮助的话,请大家来点掌声! 首先介绍java定时器(java.util.Timer) ...
- java判断邮件是否发送成功
http://www.cnblogs.com/winner-0715/p/5136392.html
- 利用工具MailUtils实现邮件的发送,遇到的大坑,高能预警!!
java实现邮件的发送依赖的jar包有两个:mail.jar和activation.jar,我也找到了一个工具包:itcast-tools-1.4.jar,实现原理大家可以查看源码,先放出资源链接 h ...
- java spring 邮件发送
开发中经常会遇到发送邮件进行用户验证,或者其它推送信息的情况,本文基于spring,完成邮件的发送,主要支持普通文本邮件的发送,html文本邮件的发送,带附件的邮件发送,没有实现群发.多个附件发送等需 ...
- 用java实现邮件发送验证码
java实现邮件发送验证码 建议不要用qq邮箱,我使用qq邮箱直接一直给我报530错误,我一直认为我代码写的有错误或者POP3/SMTP服务没弄好.所以建议注册个别的邮箱,我就申请了个网易163邮箱瞬 ...
- web基础---->java邮件的发送
这里记录一下关于java邮件发送代码的编写.你在我身边也好,在天边也罢,想到世界的角落有一个你,觉得整个世界也变得温柔安定了. java邮件的发送 一.直接贴出代码,如下: package com.c ...
- Java Mail 邮件发送简单封装
上一篇文章我们用写了一个Java Mail 的Demo,相信你已经可以用那个例子来发送邮件了.但是Demo 有很多的问题. 首先每次发送需要配置的东西很多,包括发件人的邮箱和密码.smtp服务器和SM ...
随机推荐
- FatMouse' Trade(hdoj1009)
Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding th ...
- C语言的本质(13)——指向指针的指针
指针可以指向基本类型,也可以指向复合类型,因此一个指针变量存放的可以是另一个指针变量的地址,则称这个指针变量为指向指针的指针变量.由于指针变量直接指向变量,所以称为"单级间址".而 ...
- Go语言实现-观察者模式
前前言 这个类经过我的正式投入使用啊,发现不对劲,这样做可能会导致线程死锁 比如你dispatch一个event,然后在这个回调里把那个事件的侦听给remove掉了,那么就会导致线程死锁(这个问题找了 ...
- [转]Geoserver全面了解
From:http://www.cnblogs.com/ada-zheng/archive/2013/07/16/3192921.html Geoserver是一个功能齐全,遵循OGC开放标准的开源W ...
- windows2003 64位注册码 序列号 激活码
Windows 2003 R2 64bit Enterprise VOL Edition 企业版 MR78C-GF2CY-KC864-DTG74-VMT73 VPT7T-77D38-KWVW2-2G3 ...
- #include <boost/function.hpp>
为atoi取别名fun,fun实质上是函数指针 #include <iostream> #include <boost/function.hpp> void main() { ...
- ROS Node/Topic/Message/Service的一些问题
1.Node http://blog.exbot.net/archives/1412 (摘自老王说ros) node干的什么活?callback queue里的活.这个callback queue里的 ...
- Altium designer使用技巧集(1)
1.如何生成PCB 先得新建个PCB文件(File-New-Pcb):然后保存下,在新建的PCB文件下:Design-Import Changes From PCB_PROJECT1.PRJPCB(D ...
- mac 安装maven 和改动java环境变量
一. 首先是安装maven: 步骤: 1.下载Maven tar包 http://maven.apache.org/download.cgi 2. 下载后解压到某个目录下 [html] view pl ...
- UVA10869 - Brownie Points II(线段树)
UVA10869 - Brownie Points II(线段树) 题目链接 题目大意:平面上有n个点,Stan和Ollie在玩游戏,游戏规则是:Stan先画一条竖直的线作为y轴,条件是必需要经过这个 ...