无法使用版本 8.1.2 发送电子邮件。可能是依赖关系问题?
16
0
我在发送电子邮件时遇到问题,一切似乎都很好,但它们无法启动。如果我使用版本 6,一切都很好。也许我对 8.1.2 存在依赖问题相同的代码基本上适用于...
我在发送电子邮件时遇到问题,一切似乎都很好,但它们无法启动。如果我使用版本 6,一切都很好。也许我对 8.1.2 有依赖性问题相同的代码基本上适用于 6。
Smtp 端口是 25,没有明确的 SSL 或 TLS ...
使用 jdk 11
在日志中,QUIT 之前没有出现消息正文,这真的很奇怪......
我的代码非常简单......:
//--------------------------------------------/
EmailPopulatingBuilder emailBuilder = EmailBuilder.startingBlank();
//--------------------------------------------/
MailerRegularBuilderImpl mailerBuilder = MailerBuilder.withSMTPServer(
smtp.getSmtpServer(),
smtp.getSmtpPort(),
smtp.getSmtpUser(),
smtp.getSmtpPass())
//--------------------------------------------/
mailerBuilder.verifyingServerIdentity(false);
mailerBuilder.withDebugLogging(true);
mailerBuilder.withSessionTimeout(10 * EasyLibCoreConstantsInterface.TIMEUNIT_MS_1SEC);
//--------------------------------------------/
//SSL or TLS
//--------------------------------------------/
if (smtp.isSmtpSSL() == true) {
mailerBuilder.withTransportStrategy(TransportStrategy.SMTPS);
} else if (smtp.isSmtpTLS() == true) {
mailerBuilder.withTransportStrategy(TransportStrategy.SMTP_TLS);
} else {
mailerBuilder.withTransportStrategy(TransportStrategy.SMTP);
}
//--------------------------------------------/
//PROXY
//--------------------------------------------/
if(smtp.isProxy() == true) {
if(EasyLibCoreStaticsFieldValue.checkStringEmpty(smtp.getProxyUser()) == false) {
mailerBuilder.withProxy(
smtp.getProxyHost(),
smtp.getProxyPort(),
smtp.getProxyUser(),
smtp.getProxyPass());
} else {
mailerBuilder.withProxy(smtp.getProxyHost(), smtp.getProxyPort());
}
}
//--------------------------------------------/
//FROM
//--------------------------------------------/
if(EasyLibCoreStaticsFieldValue.checkStringEmpty(email.getMittenteNome()) == false) emailBuilder.from(email.getMittenteNome(),email.getMittenteEmail());
if(EasyLibCoreStaticsFieldValue.checkStringEmpty(email.getMittenteNome()) == true) emailBuilder.from(email.getMittenteEmail());
//--------------------------------------------/
//TO
//--------------------------------------------/
if(EasyLibCoreStaticsFieldValue.checkStringEmpty(email.getDestinatarioNome()) == false) emailBuilder.to(email.getDestinatarioNome(),email.getDestinatarioEmail());
if(EasyLibCoreStaticsFieldValue.checkStringEmpty(email.getDestinatarioNome()) == true) emailBuilder.to(email.getDestinatarioEmail());
//--------------------------------------------/
emailBuilder.withSubject(email.getSoggetto());
//--------------------------------------------/
emailBuilder.withReplyTo(email.getMittenteNome(),email.getMittenteEmail());
emailBuilder.withBounceTo(email.getMittenteNome(),email.getMittenteEmail());
emailBuilder.withReturnReceiptTo(email.getMittenteNome(),email.getMittenteEmail());
emailBuilder.withDispositionNotificationTo(email.getMittenteNome(),email.getMittenteEmail());
//--------------------------------------------/
//Confirm read response
//--------------------------------------------/
emailBuilder.withHeader("X-Confirm-Reading-To", email.getMittenteEmail());
//--------------------------------------------/
//MESSAGE TYPE
//--------------------------------------------/
if(email.isIsHtml() == false) emailBuilder.withPlainText(email.getCorpo());
if(email.isIsHtml() == true) emailBuilder.withHTMLText(email.getCorpo());
//--------------------------------------------/
//Images auto-resolution
//--------------------------------------------/
emailBuilder.withEmbeddedImageAutoResolutionForFiles(true);
emailBuilder.withEmbeddedImageAutoResolutionForClassPathResources(true);
emailBuilder.withEmbeddedImageAutoResolutionForURLs(true);
//--------------------------------------------/
// allow resources outside of basedir (careful, potential security attack surface!)
//--------------------------------------------/
emailBuilder.allowingEmbeddedImageOutsideBaseDir(true);
emailBuilder.allowingEmbeddedImageOutsideBaseClassPath(true);
emailBuilder.allowingEmbeddedImageOutsideBaseUrl(true);
//--------------------------------------------/
Email emailer = emailBuilder.buildEmail();
//--------------------------------------------/
Mailer mailer = mailerBuilder.buildMailer();
//--------------------------------------------/
try {
mailer.sendMail(emailer);
} catch(Exception e) {
//--------------------------------------------/
serviceErrorDetail = "Errore invio email: " + e.getLocalizedMessage();
//--------------------------------------------/
}
依赖关系(部分)如下:
<!-- START ==================================================================== -->
<!-- Simple email send -->
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>8.11.2</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>smime-module</artifactId>
<version>8.11.2</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>authenticated-socks-module</artifactId>
<version>8.11.2</version>
</dependency>
<dependency>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>
日志跟踪:
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J(W): Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J(W): Ignoring binding found at [jar:file:/N:/Devel/maven/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J(W): See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
DEBUG: setDebug: Jakarta Mail version 2.1.3
DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,org.eclipse.angus.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=mail.server.it, user=username, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "mail.server.it", port 25, isSSL false
220 server ESMTP Postfix (Ubuntu)
DEBUG SMTP: connected to host "mail.server.it", port: 25
EHLO WOPR.mshome.net
250-server
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10240000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO WOPR.mshome.net
250-server
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10240000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: protocolConnect login, host=mail.server.it, user=username, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: pippo<[email protected]>
DATA
354 End data with <CR><LF>.<CR><LF>
Date: Fri, 13 Sep 2024 12:37:32 +0200 (CEST)
From: Server name <[email protected]>
Reply-To: Server name<[email protected]>
To: pippo<[email protected]>
Message-ID: <[email protected]>
Subject: TEST
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Confirm-Reading-To: [email protected]
Disposition-Notification-To: Destination <[email protected]>
Return-Receipt-To: Destination <[email protected]>
QUIT
DEBUG SMTP: exception reading response, THROW:
java.net.SocketTimeoutException: Read timed out
at java.base/java.net.SocketInputStream.socketRead0(Native Method)
at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:478)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:472)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1354)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:963)
at org.eclipse.angus.mail.util.TraceInputStream.read(TraceInputStream.java:107)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271)
at org.eclipse.angus.mail.util.LineInputStream.readLine(LineInputStream.java:104)
at org.eclipse.angus.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2489)
at org.eclipse.angus.mail.smtp.SMTPTransport.close(SMTPTransport.java:1401)
at org.simplejavamail.mailer.internal.util.TransportRunner.runOnSessionTransport(TransportRunner.java:82)
at org.simplejavamail.mailer.internal.util.TransportRunner.sendMessage(TransportRunner.java:56)
at org.simplejavamail.mailer.internal.SendMailClosure.executeClosure(SendMailClosure.java:69)
at org.simplejavamail.mailer.internal.AbstractProxyServerSyncingClosure.run(AbstractProxyServerSyncingClosure.java:59)
at org.simplejavamail.mailer.internal.MailerImpl.sendMail(MailerImpl.java:364)
at org.simplejavamail.mailer.internal.MailerImpl.sendMail(MailerImpl.java:349)
at it.ppu.easylib.core.statics.EasyLibCoreStaticsNetSendMail.send(EasyLibCoreStaticsNetSendMail.java:214)
at it.ppu.easylib.core.statics.EasyLibCoreStaticsNetSendMail.main(EasyLibCoreStaticsNetSendMail.java:65)
无法使用版本 8.1.2 发送电子邮件。可能是依赖关系问题?
下载声明: 本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!
下载声明: 本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!
收藏的用户(0)
X
正在加载信息~