码迷,mamicode.com
首页 > 编程语言 > 详细

JavaMail的用法---有个授权码,每天都会变的,不会弄

时间:2016-12-30 10:14:59      阅读:613      评论:0      收藏:0      [点我收藏+]

标签:student   ext   work   邮箱   org   smtp   public   array   dem   

package com.imarce.student.recruit.biz.util;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
* Created by Administrator on 2016/12/21 0021.
*/

/**
*发送邮件的test
*/
@Component
public class SendEmail {
private JavaMailSenderImpl email;

private SimpleMailMessage message;

public SendEmail() {
// email = new JavaMailSenderImpl();
// email.setHost("smtp.qq.com");
// email.setUsername("");
// email.setPassword("");//授权码
// email.setPort(465);
// Properties properties = new Properties();
// properties.put("mail.smtp.auth", true);
// properties.put("mail.smtp.ssl.enable", true);
// properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
// properties.put("mail.smtp.timeout", 25000);
// email.setJavaMailProperties(properties);
email = new JavaMailSenderImpl();
email.setHost("smtp.163.com");
email.setUsername(""); // 根据自己的情况,设置username
email.setPassword(""); // 根据自己的情况, 设置password
Properties prop = new Properties();
prop.put("mail.smtp.auth", "true"); // 将这个参数设为true,让服务器进行认证,认证用户名和密码是否正确
prop.put("mail.smtp.timeout", "25000");
email.setJavaMailProperties(prop);

}

//发送邮件
public void sendqq(){
message = new SimpleMailMessage();
message.setFrom("xxxxxxxxxx@qq.com");
message.setTo("xxxxxxxxxx@qq.com");
message.setSubject("WOW 邮箱激活");
message.setText("这个是一个通过Spring框架来发送邮件的小程序");
email.send(message);

}


public void send163(String emailAddress){
// 建立邮件消息
message = new SimpleMailMessage();
// 设置收件人,寄件人 用数组发送多个邮件
// String[] array = new String[] {"xxxxxxxx@163.com","xxxxxxxx@sohu.com"};
// mailMessage.setTo(array);

message.setFrom("xxxxxxxxxx@qq.com");
message.setTo(emailAddress);

message.setSubject("测试简单文本邮件发送!");
message.setText("测试我的简单邮件发送机制!!");
email.send(message);
}
}

JavaMail的用法---有个授权码,每天都会变的,不会弄

标签:student   ext   work   邮箱   org   smtp   public   array   dem   

原文地址:http://www.cnblogs.com/aiugu/p/6235738.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!