Google停止SMTP网关2022年5月30日?如何使用带有servlet(java)的Gmail api发送邮件,jsp
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.starttls.required", "true");
properties.put("mail.smtp.ssl.protocols", "TLSv1.2");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
您可以通过在GMAIL帐户上启用2FA身份验证来做到这一点。然后到:谷歌账号->安全→登录谷歌->应用程序的密码然后您可以为您的应用程序生成一个密码。
https://support.google.com/accounts/answer/185833