Amazon SES 邮件发送不成功 (上游OhMyEmail与SMTP标准不符导致)
Created by: GalvinGao
我的环境
Server 版本:1.2.0 Admin 版本:1.2.0 数据库:H2 运行模式:production UA 信息:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
错误日志
... 90 common frames omitted
at io.github.biezhi.ome.OhMyEmail.from(OhMyEmail.java:138) ~[oh-my-email-0.0.4.jar!/:na]
at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:119) ~[javax.mail-1.6.2.jar!/:1.6.2]
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:752) ~[javax.mail-1.6.2.jar!/:1.6.2]
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:858) ~[javax.mail-1.6.2.jar!/:1.6.2]
Caused by: javax.mail.internet.AddressException: Extra route-addr
... 88 common frames omitted
at run.halo.app.service.impl.MailServiceImpl.sendMail(MailServiceImpl.java:48) ~[classes!/:1.2.0]
at io.github.biezhi.ome.OhMyEmail.from(OhMyEmail.java:126) ~[oh-my-email-0.0.4.jar!/:na]
at io.github.biezhi.ome.OhMyEmail.from(OhMyEmail.java:140) ~[oh-my-email-0.0.4.jar!/:na]
Caused by: io.github.biezhi.ome.SendMailException: javax.mail.internet.AddressException: Extra route-addr in string ``Blog <sender@example.com> <USERNAME>'' at position 22
at java.lang.Thread.run(Thread.java:819) [na:1.8.0_222]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_222]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_222]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:108) [spring-boot-actuator-2.2.1.RELEASE.jar!/:2.2.1.RELEASE]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at run.halo.app.filter.CorsFilter.doFilter(CorsFilter.java:41) [classes!/:1.2.0]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:103) [spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at run.halo.app.security.filter.AbstractAuthenticationFilter.doFilterInternal(AbstractAuthenticationFilter.java:167) [classes!/:1.2.0]
at run.halo.app.security.filter.AdminAuthenticationFilter.doAuthenticate(AdminAuthenticationFilter.java:89) [classes!/:1.2.0]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) [undertow-servlet-2.0.27.Final.jar!/:2.0.27.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:590) [jakarta.servlet-api-4.0.3.jar!/:4.0.3]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:523) [jakarta.servlet-api-4.0.3.jar!/:4.0.3]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_222]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_222]
at run.halo.app.controller.admin.api.MailController$$EnhancerBySpringCGLIB$$5cdd39f.testMail(<generated>) ~[classes!/:1.2.0]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_222]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_222]
at sun.reflect.GeneratedMethodAccessor216.invoke(Unknown Source) ~[na:na]
at run.halo.app.core.ControllerLogAop.controller(ControllerLogAop.java:48) ~[classes!/:1.2.0]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:747) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:769) ~[spring-aop-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at run.halo.app.controller.admin.api.MailController$$FastClassBySpringCGLIB$$892427bc.invoke(<generated>) ~[classes!/:1.2.0]
at run.halo.app.controller.admin.api.MailController.testMail(MailController.java:33) ~[classes!/:1.2.0]
at run.halo.app.service.impl.MailServiceImpl.sendMail(MailServiceImpl.java:55) ~[classes!/:1.2.0]
run.halo.app.exception.EmailException: 发送邮件到 destination@example.com 失败,请检查 SMTP 服务配置是否正确
admin/index.html#/system/options
中的 SMTP 设置栏)
配置文件 (SMTP 地址:email-smtp.us-east-1.amazonaws.com
发送协议:smtp
SSL 端口:465
邮件账号: USERNAME
邮件密码: PASSWORD
发件人:Blog <sender@example.com>
期望行为
期望使用以下SMTP报文正常发送邮件:
SMTP Address:email-smtp.us-east-1.amazonaws.com
Username: USERNAME
Password: PASSWORD
SMTP FROM: Blog <sender@example.com>
请格外注意SMTP FROM
当前行为
实际使用了以下SMTP报文进行发送:
SMTP Address:email-smtp.us-east-1.amazonaws.com
Username: USERNAME
Password: PASSWORD
SMTP FROM: Blog <sender@example.com> <USERNAME>
请格外注意SMTP FROM
经过一番努力追查,在上游依赖 OhMyEmail
的组件 https://github.com/biezhi/oh-my-email/blob/master/src/main/java/io/github/biezhi/ome/OhMyEmail.java#L119-L142 发现了相关代码,其中 https://github.com/biezhi/oh-my-email/blob/master/src/main/java/io/github/biezhi/ome/OhMyEmail.java#L137 直接append了邮箱账号作为了发件方。
Amazon SES的邮箱账号与密码是一组生成的随机字符串,指定发件方邮箱地址需要在 SMTP的FROM
中指定,例如已经验证的可作为发送邮件的邮箱域名为 example.com
,则可使用 Foo <bar@example.com>
, Alice <alice@example.com>
等进行发送,收件方会看到相对应的邮件发送方地址。然而 OhMyEmail
则直接拼接了邮箱账号,并不是一合法邮箱地址,会造成调用Amazon SES方服务出错。
建议解决方案
考虑到上游依赖好像不怎么维护了,个人建议可以更换到其他符合 SMTP
实现标准的邮件依赖,亦或者自行实现一套简易的邮件client。
如果可以解决这个问题就太感谢啦~