gpt4 book ai didi

java - 简单的 Java 邮件。无法在 EHLO 中设置本地主机名称(如何设置 mail.smtp.localhost?)

转载 作者:行者123 更新时间:2023-12-02 10:13:15 25 4
gpt4 key购买 nike

我在程序中使用简单 Java 邮件库 ( http://www.simplejavamail.org ),并且我想设置一个本地主机名称,当我发送电子邮件时,该名称应在 EHLO 中发送。我尝试这样做:

Properties props = new Properties();
props.put("mail.smtp.sendpartial", "true");
props.put("mail.smtp.host", "smtp.mail.ru");
props.put("mail.smtp.localhost", "mail.ru");

Mailer mailer = MailerBuilder
.withSMTPServer(server, port, login, password)
.withTransportStrategy(TransportStrategy.SMTPS)
.withSessionTimeout(10 * 1000)
.clearEmailAddressCriteria()
.withProperties(props)
.withDebugLogging(true)
.buildMailer();

正如您在代码中看到的那样,我现在应该在 EHLO 中包含“mail.ru”,但它没有发生,我仍然保留着我的计算机的名称。我在日志中看到以下内容:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mail.ru", port 465, isSSL true
220 smtp46.i.mail.ru ESMTP ready (Looking for Mail for your domain? Visit https://biz.mail.ru)
DEBUG SMTP: connected to host "smtp.mail.ru", port: 465

EHLO MyComputersName
250-smtp46.i.mail.ru
250-SIZE 73400320
250-8BITMIME
250-PIPELINING
250 AUTH PLAIN LOGIN XOAUTH2
DEBUG SMTP: Found extension "SIZE", arg "73400320"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN XOAUTH2"
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded

我做错了什么?如何设置mail.smtp.localhost?

最佳答案

如果启用了 SSL,请尝试 mail.smtps.localhostmail.smtps.localaddress。否则,可以使用 mail.smtp.localhostmail.smtp.localaddress

在您的情况下,使用了TransportStrategy.SMTPS,这意味着显式启用了SSL,因此用于普通连接的mail.smtp.localhost将不起作用。

下面是我的引用[从 SMTPTransport 类文件粘贴]:

public synchronized String getLocalHost() {
if(this.localHostName == null || this.localHostName.length() <= 0) {
***this.localHostName = this.session.getProperty("mail." + this.name + ".localhost");***
}

if(this.localHostName == null || this.localHostName.length() <= 0) {
***this.localHostName = this.session.getProperty("mail." + this.name + ".localaddress");***
}

InetAddress localHost;
try {
if(this.localHostName == null || this.localHostName.length() <= 0) {
localHost = InetAddress.getLocalHost();
this.localHostName = localHost.getCanonicalHostName();
if(this.localHostName == null) {
this.localHostName = "[" + localHost.getHostAddress() + "]";
}
}
} catch (UnknownHostException var2) {
;
}

if((this.localHostName == null || this.localHostName.length() <= 0) && this.serverSocket != null && this.serverSocket.isBound()) {
localHost = this.serverSocket.getLocalAddress();
this.localHostName = localHost.getCanonicalHostName();
if(this.localHostName == null) {
this.localHostName = "[" + localHost.getHostAddress() + "]";
}
}

return this.localHostName;
}

关于java - 简单的 Java 邮件。无法在 EHLO 中设置本地主机名称(如何设置 mail.smtp.localhost?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54848702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com