且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用java程序发送电子邮件[SMTP]

更新时间:2021-09-26 07:34:11

只需在网上搜索java smtp gmail,就可以知道如何设置使用Gmail SMTP服务器的属性:

Just search the web for something like "java smtp gmail" to know how to set the properties for using the Gmail SMTP server:
Properties properties = new Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");

Session session = Session.getInstance(props,
    new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(username, password);
    }
});

另请注意,您必须配置已使用的GMail帐户(在发件人字段中指定以及传递的凭据)允许从不受信任的应用程序发送邮件。



您不应发布有效的电子邮件地址。我建议使用绿色的改善问题链接编辑您的问题以删除用户名。

Note also that you must configure the used GMail account (specified in the From field and which credentials are passed) to allow mails to be send from untrusted applications.

You should not post valid email addresses. I suggest to edit your question using the green 'Improve question' link to remove the user names.