发送邮件javax.mail没有认证 [英] Send mail in javax.mail without authentication

查看:580
本文介绍了发送邮件javax.mail没有认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javax.mail在Java中发送邮件。
现在,我的项目的概念的一部分,改变了我要送邮件无需认证。我将不得不改变我的了createSession()方法:

 私人无效了createSession(){
    properties.put(mail.smtp.auth,真);
    properties.put(mail.smtp.starttls.enable,真);
    properties.put(mail.smtp.host,服务器);
    properties.put(mail.smtp.port,口);    会话= Session.getInstance(属性,新javax.mail.Authenticator(){
        受保护的PasswordAut​​hentication的getPasswordAut​​hentication(){
            返回新的PasswordAut​​hentication(用户名,密码);
        }
    });
}

这是相当明显,我应该改变 mail.smtp.auth ,但还有什么我应该改变?


解决方案

 私人无效了createSession(){
    properties.put(mail.smtp.auth,假);
     //下面把为false,如果不需要HTTPS
    properties.put(mail.smtp.starttls.enable,真);
    properties.put(mail.smtp.host,服务器);
    properties.put(mail.smtp.port,口);    会话= Session.getInstance(属性);
}

我想,这就够了。

I am using javax.mail to send mails in Java. Now that a part of the concept of my project changed I have to send a mail without authentication. I will have to change my createSession() method:

private void createSession() {
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.host", server);
    properties.put("mail.smtp.port", port);

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

It is rather obvious that I should change mail.smtp.auth to false, but what else should I change?

解决方案

private void createSession() {
    properties.put("mail.smtp.auth", "false");
     //Put below to false, if no https is needed
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.host", server);
    properties.put("mail.smtp.port", port);

    session = Session.getInstance(properties);
}

I think, this would suffice.

这篇关于发送邮件javax.mail没有认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆