Java对接⾕歌邮箱-代码及其⾕歌邮箱账号配置⾸先登录Gmail账号
唐三最后被谁杀了到这个地⽅
然后查看所有配置
然后贴代码:
private static String from = "youAccount@gmail";//发送者的⾕歌邮箱
黄秋生为什么被大陆封
private static String password = "password";//⾕歌邮箱密码
public static boolean sendMailGMail(String to, String content) {
return gmailSender(from,password,to,"标题", content);
}
private static void gmailSsl(Properties props) {
final String SSL_FACTORY = "javax.ssl.SSLSocketFactory";
props.put("mail.debug", "true");女明星毛都漏了图片
props.put("mail.smtp.host", "ail");
罗嘉良 苏岩props.put("mail.able", "true");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.port", "465");
//props.put("mail.smtp.port", "587");
props.put("mail.smtp.socketFactory.port", "465");
//props.put("mail.smtp.socketFactory.port", "587");
明道 阮经天props.put("mail.smtp.auth", "true");
}
public static boolean gmailSender(String from,String password,String email,String    subject,String content) {
Properties props = new Properties();
西湖十景图
gmailSsl(props);
Session session = DefaultInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, password);
}
});
Message msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(email));
msg.setSubject(subject);
msg.setText(content);
msg.setSentDate(new Date());
Transport.send(msg);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
return true;
}
到此别以为就能发送了  哈哈哈  我也是这么认为,但是还发送不了  提⽰了
那这个时候就需要修改⼀下⾕歌账号配置了:
⾄此,点击发送就能发送啦踩坑不易,点个赞吧~