环境:jdk8,maven
需要的pom,高版本发送会验证spf,这个不会
现在发送邮件的FROM的域名必须和发送邮件的app在同一地址
javax.mail
javax.mail-api
1.5.6
纯文本邮件内容发送
public class MailUtil {
private final static String FROM = "**@**.com";
public static void main(String[] args) {
String mail ="***@**.com";
String smtp = getSmtpByEmail(mail);
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", smtp);
props.put("mai.smtp.auth", "false");
Session session = Session.getInstance(props, null);
MimeMessage msg= new MimeMessage(session);
try {
msg.setFrom(FROM);
msg.setSubject("紧急通知","gb2312");