谷歌邮件发送协议
⾕歌邮件发送协议
怎么注册gmail邮箱import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
ail.utils.DefaultMessage;
/**
* 作者: 薛俊鹏
* 时间: 2018年9⽉30⽇下午4:23:49
* 内容: ⾕歌邮件发送
* 注:⽹络需要
* 状态: 编写
*/
public class GoogleMail {
/*
* gmail邮箱SSL⽅式
*/
private static void gmailssl(Properties props) {
final String SSL_FACTORY = "javax.ssl.SSLSocketFactory";
props.put("mail.debug", "false");
props.put("mail.smtp.host", ailServer);
props.put("mail.able", "true");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.port", ailSerPort);
props.put("mail.smtp.socketFactory.port", ailFacPort);
props.put("mail.smtp.auth", "true");
}
/
*list_to:收件⼈、 list_cc:抄送⼈  */
public static boolean GmailSender(List<String> list_to,List<String> list_cc,String Context,String subject) {
// Get a Properties object
Properties props = new Properties();
boolean IsSend = true;
//选择ssl⽅式
gmailssl(props);
Session session = DefaultInstance(props,new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new ailAccount, ailPassword);                    }
});
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
try {
msg.setFrom(new ailAccount));
/*邮件发送*/
for(Object receiveMail:list_to){
msg.setRecipients(Message.RecipientType.TO,InternetAddress.String()));                msg.setSubject(subject);
msg.setText(Context);
msg.setSentDate(new Date());
Transport.send(msg);
}
/*邮件抄送*/
for(Object copyMail:list_cc){
msg.setRecipients(Message.RecipientType.CC,InternetAddress.String()));                msg.setSubject(subject);
msg.setText(Context);
msg.setSentDate(new Date());
Transport.send(msg);
}
} catch (Exception e) {
IsSend = false;
System.out.println("邮件发送请求超时,请查看⾕歌邮箱相关协议规范【 Send by Service.】");
}
return IsSend;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。