Apache commons邮件Exception ..Recipient地址被拒绝:虚拟别名表

时间:2016-02-15 06:12:30

标签: java apache email apache-commons-email

我有两封自己域名的电子邮件。一个在域中配置,另一个在gmail(admin.google.com)中配置。

我的代码

    HtmlEmail htmlEmail = new HtmlEmail();
    htmlEmail.setHostName("mydomain.com");
    htmlEmail.setSmtpPort(587);
    htmlEmail.setAuthenticator(new DefaultAuthenticator(
            "enquiry@mydomain.com", "password"));


        htmlEmail.setFrom("enquiry@mydomain.com", " Enquiry");
        htmlEmail.setSubject("New Enquiry");
        htmlEmail.setHtmlMsg("My message");
        htmlEmail.addTo("info@mydomain.com");

        htmlEmail.send();

当我从域配置的电子邮件(enquiry@mydomain.com)向gmail配置的电子邮件(info@mydomain.com)发送邮件时,它显示以下错误:

  

org.apache.commons.mail.EmailException:将电子邮件发送给   以下服务器失败:mydomain.com:587
  在org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
  在org.apache.commons.mail.Email.send(Email.java:1448)
  在com.myproject.test.HomeController.sendEmail(HomeController.java:153)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  在java.lang.reflect.Method.invoke(未知来源)
  在org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)     在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)     在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)     在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)     在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)     在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)     在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)     在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)     在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)     在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)   在javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
  在javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
  在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)     在   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:659)     在   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:147)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:279)     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)     在   org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(未知来源)引起:   javax.mail.SendFailedException:无效的地址;嵌套异常   是:com.sun.mail.smtp.SMTPAddressFailedException:550 5.1.1   :收件人地址被拒绝:用户未知   虚拟别名表   com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1949)at   com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1195)     在javax.mail.Transport.send0(Transport.java:254)at   javax.mail.Transport.send(Transport.java:124)at   org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)..39   更多原因:com.sun.mail.smtp.SMTPAddressFailedException:550   5.1.1:拒绝收件人地址:虚拟别名表中的用户未知   com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1802)

1 个答案:

答案 0 :(得分:0)

根本原因似乎是@Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); sendNotification(message); } private void sendNotification(String message) { Intent intent = new Intent(this, YOURCLASS.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_park_notification) .setContentTitle("Ppillo Message") .setContentText(message) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } ,这表示您要发送的SMTP服务器拒绝该电子邮件,因为它不知道您指定的电子邮件地址。

因此,要么电子邮件地址不正确,要么需要正确配置SMTP服务器以接受您在N^3Recipient address rejected: User unknown in virtual alias table字段中指定的电子邮件地址。