1

最近我开始使用 Amazon SES。我的第一次尝试是使用端口 25,但我遇到了很多连接问题。经过一番搜索,我发现 EC2 限制了端口 25 的流量以避免垃圾邮件,因此我更改为端口 587,但是从每天大约 1000 封电子邮件中,我的应用程序中大约有五次出现 SMTP 连接异常。

我认为它是随机的,因为少数失败的电子邮件位于应用程序的不同部分,我没有发现它们之间的任何模式。

我的发送配额是 10000,电子邮件中的收件人少于 50 个。有时发送失败是否正常?

提前致谢。

我正在使用具有以下设置的 apache commons email 1.3.2:

setCharset("UTF-8");
setHostName("email-smtp.us-east-1.amazonaws.com");
setFrom("..."); // email from a verified domain
setAuthentication("...", "..."); // amazon smtp credentials
setSmtpPort(587);
setStartTLSEnabled(true);
setStartTLSRequired(true);

例外:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : email-smtp.us-east-1.amazonaws.com:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at br.com.spdata.email.HtmlEmail.send(HtmlEmail.java:136)
    at br.com.spdata.persistence.mysql.service.chat.AtendimentoService.doEnviarCopiaPorEmail(AtendimentoService.java:1112)
    at br.com.spdata.persistence.mysql.service.chat.AtendimentoService.access$000(AtendimentoService.java:62)
    at br.com.spdata.persistence.mysql.service.chat.AtendimentoService$1.run(AtendimentoService.java:1036)
    at java.lang.Thread.run(Thread.java:744)
Caused by: javax.mail.AuthenticationFailedException: [EOF]
    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 6 more

|

java.lang.RuntimeException: org.apache.commons.mail.EmailException: Sending the email to the following server failed : email-smtp.us-east-1.amazonaws.com:587
    at br.com.spdata.jsf.util.JsfUtil.handleException(JsfUtil.java:236)
    at br.com.spdata.tecnico.page.agenda.AutorizacaoVisitaController.persist(AutorizacaoVisitaController.java:192)
    at sun.reflect.GeneratedMethodAccessor2446.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIData.broadcast(UIData.java:1106)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at br.com.spdata.tecnico.filter.ExceptionFilter.doFilter(ExceptionFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at com.googlecode.psiprobe.Tomcat70AgentValve.invoke(Tomcat70AgentValve.java:38)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : email-smtp.us-east-1.amazonaws.com:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at br.com.spdata.email.HtmlEmail.send(HtmlEmail.java:136)
    at br.com.spdata.persistence.mysql.service.ScAgendaService.sendEmailConfirmacaoAgendamento(ScAgendaService.java:975)
    at br.com.spdata.tecnico.page.agenda.AutorizacaoVisitaController.persist(AutorizacaoVisitaController.java:168)
    ... 56 more
Caused by: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
    java.net.SocketException: Connection closed by remote host
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2163)
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2150)
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2074)
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2111)
    at com.sun.mail.smtp.SMTPTransport.data(SMTPTransport.java:1887)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 60 more
Caused by: java.net.SocketException: Connection closed by remote host
    at sun.security.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1490)
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:70)
    at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:114)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
    at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2161)
    ... 68 more

|

org.apache.commons.mail.EmailException: Sending the email to the following server failed : email-smtp.us-east-1.amazonaws.com:587
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
    at org.apache.commons.mail.Email.send(Email.java:1437)
    at br.com.spdata.email.HtmlEmail.send(HtmlEmail.java:136)
    at br.com.spdata.persistence.mysql.service.chat.AtendimentoService.notificarChatSemAtendente(AtendimentoService.java:1541)
    at br.com.spdata.persistence.model.chat.AbstractAtendimentoBean.handleChatSemAtendente(AbstractAtendimentoBean.java:310)
    at br.com.spdata.persistence.model.chat.AbstractAtendimentoBean.entrar(AbstractAtendimentoBean.java:295)
    at br.com.spdata.cliente.page.atendimento.AtendimentoBean.entrar(AtendimentoBean.java:106)
    at sun.reflect.GeneratedMethodAccessor1416.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:101)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at br.com.spdata.cliente.filter.ExceptionFilter.doFilter(ExceptionFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at br.com.spdata.cliente.filter.LoginFilter.doFilter(LoginFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at com.googlecode.psiprobe.Tomcat70AgentValve.invoke(Tomcat70AgentValve.java:38)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: javax.mail.MessagingException: Exception reading response;
  nested exception is:
    java.net.SocketException: Connection reset
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2210)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1950)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
    ... 50 more
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
    at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2188)
    ... 58 more
4

2 回答 2

0

您必须确保您没有超过发送限制和发送速率 - 听起来您在发送配额之内,但也许您超出了允许的发送速率:

  • 发送配额— 您可以在 24 小时内发送的最大电子邮件数量。发送配额反映滚动时间段。每次您尝试发送电子邮件时,Amazon SES 都会检查您在过去 24 小时内发送了多少封电子邮件。

  • 最大发送速率— 您每秒可以发送的最大电子邮件数。您可以在短时间内超过此限制,但不能持续一段时间。

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/manage-sending-limits.html

此外,您似乎是在说有时您在一封电子邮件中列出了 50 个 +/- 收件人。AWS SES 建议您将电子邮件限制为一位收件人。

http://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-email.html

于 2013-12-13T12:10:12.560 回答
0

通过使用端口 465 的 SMTPS 解决了该问题。

Commons Email 似乎不能很好地处理 SSL,因为 isSSL 在调试模式下总是显示为 false。所以我覆盖了 HtmlEmail 的发送方法:

@Override
public String send() throws EmailException
{
    buildMimeMessage();

    // Implementação padrão de send() não conecta corretamente via SSL
    Transport transport = null;
    try
    {
        message.saveChanges();

        transport = getMailSession().getTransport("smtps");
        transport.connect("email-smtp.us-east-1.amazonaws.com", 465, <<amazon SMTP username>>, <<amazon SMTP pasword>>);
        transport.sendMessage(message, message.getAllRecipients());

        return message.getMessageID();
    }
    catch(MessagingException e)
    {
        throw new EmailException(e);
    }
    finally
    {
        if(transport != null)
        {
            try
            {
                transport.close();
            }
            catch(MessagingException e)
            {
                throw new EmailException(e);
            }
        }
    }
}
于 2013-12-17T17:04:40.457 回答