3

我正在尝试通过 google SMTP 发送电子邮件。

该代码在我的本地 Windows PC 中的 tomcat 中运行良好。但是我在我的 centos VPS 上遇到了这个错误

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:465 

这是代码,请检查它 -

// Create the email message
HtmlEmail email = new HtmlEmail();

email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);

email.addTo(e_mail, f_name+" "+l_name);
email.setFrom("me@gmail.com", "something.com - Account activation");
email.setSubject("something.com - Account activation email");

  // embed the image and get the content id
URL url = new URL("http://something.com/out.php/i6964_logo-email.gif");
String cid = email.embed(url, "BizzKiss logo");

  // set the html message
email.setHtmlMsg("<html><body>Something</body></html>");

  // set the alternative message
email.setTextMsg("Your email client does not support HTML messages");
email.setTLS(true);
  // send the email
email.send();

out.println("Email sent to "+e_mail+"<br/>Please check your email for activation message.Not found? Please check your spam folder.");



org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.googlemail.com:465
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1401)
    at org.apache.commons.mail.Email.send(Email.java:1428)
    at org.apache.jsp.email_jsp._jspService(email_jsp.java:104)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    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 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    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:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    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:724)
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14  Please log in via your web browser and then try again.
534-5.7.14 Learn more at https://support.google.com/mail/bin/answer.py?answer=787
534 5.7.14 54 qf7sm12328634pac.14 - gsmtp

    at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
    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:1391)
    ... 30 more

请检查堆栈跟踪并告诉我出了什么问题

4

5 回答 5

16

即使 Gmail 帐户凭据正确,Google 仍可能阻止身份验证尝试,怀疑是机器人邮件发件人。要修复它,请确保您在浏览器中使用相同的 Gmail 帐户登录,然后打开下面的链接并逐步完成验证过程:

https://accounts.google.com/b/0/DisplayUnlockCaptcha

这将允许您在大约 10 分钟内访问您的 Gmail 帐户。请务必在此时间范围内尝试您的代码。

这个技巧大约在半年前帮助了我,希望从那时起没有任何改变。

于 2013-09-08T19:01:28.577 回答
9

每当脚本尝试自动登录时,Gmail 通常会阻止该脚本。要通过脚本启用登录,请执行以下操作:

  1. 去这里 https://security.google.com/settings/security/activity?hl=en&pli=1
  2. 在登录列表中,选择被阻止并包含您服务器 IP 的登录。
  3. 在异常活动下单击更改并将活动识别为您的活动。

如果列表中没有活动,请转到https://accounts.google.com/b/0/DisplayUnlockCaptcha,然后尝试。

这两种技巧都为我工作了很多次。

于 2014-02-28T18:08:33.750 回答
0

如果您使用 SMTP,您的主机名必须是smtp.gmail.com并且端口号可以是465 或 587。您的错误日志提示您的用户名或密码错误,因此请确保您的帐户凭据并重试。请查看此google 邮件客户端链接。

于 2013-09-18T14:14:07.420 回答
0

要启用通过 gmail 发送邮件,您必须禁用 gmail 帐户中的一些安全选项:请参阅https://support.google.com/accounts/answer/6010255

于 2015-03-30T00:09:26.883 回答
0

我被挂断了...确保将“协议”设置为 SMTP+SSL。否则请按照此处的说明进行操作:https ://confluence.jetbrains.com/display/TCD8/Setting+up+Google+Mail+and+Google+Talk+as+Notification+Servers

于 2018-03-10T00:56:30.787 回答