首页 > 代码库 > java 邮箱发送
java 邮箱发送
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sendmail;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
*
* @author hgh
*/
public class sdm {
public static void main(String[] args) {
System.out.println("启动成功");
try {
int port = 25;
String server = "smtp.163.com";//邮件服务器mail.cpip.net.cn
// String from = "shengchan@yntacc.com";//发送者,显示的发件人名字
String from = "pjzkmail@163.com";//发送者,显示的发件人名字
// String user = "shengchan@yntacc.com";//发送者邮箱地址
String user = "pjzkmail@163.com";//发送者邮箱地址
String password = "NMFsqa6HnV1t91Iu";//密码
//建立会话
Properties props = new Properties();
props.put("mail.smtp.host", server);
props.put("mail.smtp.port", String.valueOf(port));
props.put("mail.smtp.auth", "true");
Transport transport = null;
Session session = Session.getInstance(props);
//建立信息
Message msg = new MimeMessage(session);
//发件人
msg.setFrom(new InternetAddress(from));
String toList = "124926249@qq.com";
InternetAddress[] iaToList = new InternetAddress().parse(toList);
//收件人
msg.setRecipients(Message.RecipientType.TO, iaToList);
// 发送日期
msg.setSentDate(new Date());
// 主题
msg.setSubject("测试标题");
msg.setContent("测试内容", "text/html;charset=utf8"); //内容
// 邮件服务器进行验证
transport = session.getTransport("smtp");
transport.connect(server, user, password);
// bluebit_cn是用户名,xiaohao是密码
transport.sendMessage(msg, msg.getAllRecipients()); // 发送
System.out.println("邮件发送成功");
} catch (Exception e) {
e.printStackTrace();
}
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sendmail;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
*
* @author hgh
*/
public class sdm {
public static void main(String[] args) {
System.out.println("启动成功");
try {
int port = 25;
String server = "smtp.163.com";//邮件服务器mail.cpip.net.cn
// String from = "shengchan@yntacc.com";//发送者,显示的发件人名字
String from = "pjzkmail@163.com";//发送者,显示的发件人名字
// String user = "shengchan@yntacc.com";//发送者邮箱地址
String user = "pjzkmail@163.com";//发送者邮箱地址
String password = "NMFsqa6HnV1t91Iu";//密码
//建立会话
Properties props = new Properties();
props.put("mail.smtp.host", server);
props.put("mail.smtp.port", String.valueOf(port));
props.put("mail.smtp.auth", "true");
Transport transport = null;
Session session = Session.getInstance(props);
//建立信息
Message msg = new MimeMessage(session);
//发件人
msg.setFrom(new InternetAddress(from));
String toList = "124926249@qq.com";
InternetAddress[] iaToList = new InternetAddress().parse(toList);
//收件人
msg.setRecipients(Message.RecipientType.TO, iaToList);
// 发送日期
msg.setSentDate(new Date());
// 主题
msg.setSubject("测试标题");
msg.setContent("测试内容", "text/html;charset=utf8"); //内容
// 邮件服务器进行验证
transport = session.getTransport("smtp");
transport.connect(server, user, password);
// bluebit_cn是用户名,xiaohao是密码
transport.sendMessage(msg, msg.getAllRecipients()); // 发送
System.out.println("邮件发送成功");
} catch (Exception e) {
e.printStackTrace();
}
}
}
java 邮箱发送
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。