1

最近、Amazon SES を使い始めました。私の最初の試みはポート 25 を使用することでしたが、多くの接続の問題がありました。いくつか検索した結果、EC2 はスパムを避けるためにポート 25 のトラフィックを抑制していることがわかったので、ポート 587 に変更しましたが、毎日約 1000 通の電子メールから、約 5 回、アプリケーションで 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 時間に送信できるメールの最大数。送信クォータはローリング期間を反映しています。E メールを送信しようとするたびに、Amazon SES は過去 24 時間に送信した E メールの数をチェックします。

  • 最大送信レート— 1 秒あたりに送信できる電子メールの最大数。短いバーストの場合はこの制限を超えることができますが、持続的な期間は超えられません。

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

また、1 つのメールに 50 +/- の受信者がリストされている場合があると言っているようです。AWS SES では、E メールを 1 人の受信者に限定することをお勧めします。

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

于 2013-12-13T12:10:12.560 に答える
0

ポート 465 で SMTPS を使用して問題を解決しました。

isSSL はデバッグ モードでは常に false として表示されるため、Commons Email は SSL を適切に処理していないようです。そこで、HtmlEmail の send メソッドをオーバーライドしました。

@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 に答える