嗨,我正在尝试从我的 springboot 应用程序发送电子邮件,它工作完美,但只是在本地主机上。当我尝试将其放在 vps 上时,出现此错误,我看到我的 vps 正常连接并验证到 SMTP 服务器,但最终由于某种原因发送失败。我的 vps 上没有防火墙,有人知道为什么会发生这种情况吗?谢谢!
DEBUG: setDebug: Jakarta Mail version 2.0.1
DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=wes1-smtp.wedos.net, [email protected], password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "wes1-smtp.wedos.net", port 587, isSSL false
220 wes1-so2.wedos.net ESMTP Postfix - S.T.A.N.D.A. postak OUT
DEBUG SMTP: connected to host "wes1-smtp.wedos.net", port: 587
EHLO 5575e5731be3
250-wes1-so2.wedos.net
250-PIPELINING
250-SIZE 104857600
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "104857600"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO 5575e5731be3
250-wes1-so2.wedos.net
250-PIPELINING
250-SIZE 104857600
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "104857600"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: protocolConnect login, host=wes1-smtp.wedos.net, [email protected], 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: [email protected]
DATA
354 End data with <CR><LF>.<CR><LF>
Date: Tue, 30 May 2023 18:08:21 +0000 (UTC)
From: [email protected]
To: [email protected]
Message-ID: <1085117917.0.1685470101618@5575e5731be3>
Subject: Email Subject
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
QUIT
DEBUG SMTP: exception reading response, THROW:
java.net.SocketTimeoutException: Read timed out
at java.base/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:283)
at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:309)
at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:350)
at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:803)
at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966)
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:1455)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1059)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:102)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:244)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:263)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:100)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2456)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1396)
at org.simplejavamail.mailer.internal.util.TransportRunner.runOnSessionTransport(TransportRunner.java:74)
at org.simplejavamail.mailer.internal.util.TransportRunner.sendMessage(TransportRunner.java:51)
at org.simplejavamail.mailer.internal.SendMailClosure.executeClosure(SendMailClosure.java:69)
at org.simplejavamail.mailer.internal.AbstractProxyServerSyncingClosure.run(AbstractProxyServerSyncingClosure.java:56)
at org.simplejavamail.mailer.internal.MailerImpl.sendMail(MailerImpl.java:363)
at org.simplejavamail.mailer.internal.MailerImpl.sendMail(MailerImpl.java:348)
at cz.digikyblik.main.services.EmailService.simpleMail(EmailService.java:63)
at cz.digikyblik.main.services.BucketService.lambda$createBucket$0(BucketService.java:79)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
org.simplejavamail.mailer.internal.MailerException: Failed to send email [ID: '<1085117917.0.1685470101618@5575e5731be3>'], reason: Unknown error
at org.simplejavamail.mailer.internal.SendMailClosure.handleException(SendMailClosure.java:85)
at org.simplejavamail.mailer.internal.SendMailClosure.executeClosure(SendMailClosure.java:76)
at org.simplejavamail.mailer.internal.AbstractProxyServerSyncingClosure.run(AbstractProxyServerSyncingClosure.java:56)
at org.simplejavamail.mailer.internal.MailerImpl.sendMail(MailerImpl.java:363)
at org.simplejavamail.mailer.internal.MailerImpl.sendMail(MailerImpl.java:348)
at cz.digikyblik.main.services.EmailService.simpleMail(EmailService.java:63)
at cz.digikyblik.main.services.BucketService.lambda$createBucket$0(BucketService.java:79)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.RuntimeException: Provider for jakarta.activation.spi.MailcapRegistryProvider cannot be found
at jakarta.activation.FactoryFinder.find(FactoryFinder.java:90)
at jakarta.activation.MailcapCommandMap.getImplementation(MailcapCommandMap.java:696)
at jakarta.activation.MailcapCommandMap.loadFile(MailcapCommandMap.java:284)
at jakarta.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:154)
at jakarta.activation.CommandMap.getDefaultCommandMap(CommandMap.java:60)
at jakarta.activation.DataHandler.getCommandMap(DataHandler.java:128)
at jakarta.activation.DataHandler.getDataContentHandler(DataHandler.java:590)
at jakarta.activation.DataHandler.writeTo(DataHandler.java:290)
at jakarta.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1670)
at jakarta.mail.internet.MimeMessage.writeTo(MimeMessage.java:1888)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1300)
at org.simplejavamail.mailer.internal.util.TransportRunner.lambda$sendMessage$0(TransportRunner.java:53)
at org.simplejavamail.mailer.internal.util.TransportRunner.runOnSessionTransport(TransportRunner.java:73)
at org.simplejavamail.mailer.internal.util.TransportRunner.sendMessage(TransportRunner.java:51)
at org.simplejavamail.mailer.internal.SendMailClosure.executeClosure(SendMailClosure.java:69)
... 12 more
Suppressed: jakarta.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketTimeoutException: Read timed out
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2476)
at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1396)
at org.simplejavamail.mailer.internal.util.TransportRunner.runOnSessionTransport(TransportRunner.java:74)
... 14 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.base/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:283)
at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:309)
at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:350)
at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:803)
at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966)
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:1455)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1059)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:102)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:244)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:263)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:100)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2456)
... 16 more
编辑 这是代码,但就像我说的,当我在本地主机上运行它并立即发送它时,它可以正常工作。
public void simpleMail() {
Email email = EmailBuilder.startingBlank()
.from("[email protected]")
.to("[email protected]")
.withSubject("Email Subject")
.withPlainText("Email Body")
.buildEmail();
Mailer mailer = MailerBuilder
.withSMTPServer("wes1-smtp.wedos.net", 587, "mail", "pass")
.withTransportStrategy(TransportStrategy.SMTP_TLS)
.buildMailer();
mailer.getSession().setDebug(true);
try {
mailer.sendMail(email);
} catch (MailException e) {
e.printStackTrace();
}
}
某些 VPS 提供商要求您配置出站网络通信的安全网络。在某些情况下,您可能需要配置出站规则以允许从 Spring Boot 应用程序到 SMTP 服务器的通信并允许发送电子邮件。