android studio邮件开发记录
MyAuthenticator.java
/*
* Copyright (c)2016 thatluck
* 版权所有,违者必究
*/
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class MyAuthenticator extends Authenticator {
String userName = null;
String password = null;
public MyAuthenticator() {
}
public MyAuthenticator(String username, String password) {
this.userName = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
}
MailService.java
/*
* Copyright (c)2016 thatluck
* 版权所有,违者必究
*/
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailService {
public static void send_email(String content) throws IOException, MessagingException{
Properties properties = new Properties();
String to = "收信地址";
String subject ="提交日志";
properties.put("mail.smtp.host", "smtp.qq.com");
properties.put("mail.smtp.port", "465");
properties.setProperty("mail.debug", "true");
properties.setProperty("mail.smtp.auth", "true");
// 协议名称设置为smtps,会使用SSL
properties.setProperty("mail.transport.protocol", "smtps");
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.socketFactory.fallback"