首页 > 代码库 > JavaMail的用法---有个授权码,每天都会变的,不会弄

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

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的用法---有个授权码,每天都会变的,不会弄