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;
}
到此别以为就能发送了 哈哈哈 我也是这么认为,但是还发送不了 提⽰了
那这个时候就需要修改⼀下⾕歌账号配置了:
⾄此,点击发送就能发送啦踩坑不易,点个赞吧~
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论