2014-10-27 36 views
4

我知道这一定很可能是一个非常简单的问题,但我在这个问题上困扰了许多小时,在互联网上进行大量的研究之后,我没有发现问题。在JHipster(Spring)项目上配置邮件

我开始了一个jhipster项目,现在我正在尝试配置一个电子邮件服务器用于向我的新用户发送注册电子邮件。所以我编辑的存在在项目中2的配置文件:

../src/test/resources/config/application.yml

../src/main/resources/config/application.yml

在这些每一个我添加以下行下的“春天:邮件:”

host: smtp.gmail.com 
    port: 25 
    user: [email protected] 
    password: xxx 
    protocol: smtp 
    tls: true 
    auth: true 
    from: [email protected] 

然后我试图做一个新的登记和没有工作的确认邮件,我也试着运行测试,明确地从“mailService”调用函数“sendEmail”,它也没有工作ķ。有人知道为什么吗?我是否犯了一些配置错误?还有什么我应该做的?

增加关于日志的信息问:

通常这是我得到的日志当我运行它调用sendmail的功能测试:

[DEBUG] org.portotech.perdigao.config.AsyncConfiguration - Creating Async Task Executor<br> 
[DEBUG] org.portotech.perdigao.config.MetricsConfiguration - Registering JVM gauges<br> 
[DEBUG] org.portotech.perdigao.config.CacheConfiguration - No cache<br> 
[WARN] org.portotech.perdigao.Application - No Spring profile configured, running with default configuration<br> 
[DEBUG] org.portotech.perdigao.config.MailConfiguration - Configuring mail server<br> 
[INFO] org.portotech.perdigao.config.ThymeleafConfiguration - loading non-reloadable mail messages resources<br> 
[DEBUG] org.portotech.perdigao.config.DatabaseConfiguration - Configuring Mongeez<br> 
[DEBUG] org.portotech.perdigao.service.MailService - Send e-mail[multipart 'false' and html 'false'] to '[email protected]' with subject 'test' and content=test<br> 
[INFO] org.portotech.perdigao.config.CacheConfiguration - Remove Cache Manager metrics<br> 
[INFO] org.portotech.perdigao.config.CacheConfiguration - Closing Cache Manager<br> 
Disconnected from the target VM, address: '127.0.0.1:51831', transport: 'socket'<br> 
Process finished with exit code 0 

因此,未发送的电子邮件,但我没有收到任何错误消息。您发布的评论后,我打开我的IDE再次(的IntelliJ)到日志张贴在这里复制,并得到了以下日志:

[DEBUG] org.portotech.perdigao.config.AsyncConfiguration - Creating Async Task Executor<br> 
[DEBUG] org.portotech.perdigao.config.MetricsConfiguration - Registering JVM gauges<br> 
[DEBUG] org.portotech.perdigao.config.CacheConfiguration - No cache<br> 
[WARN] org.portotech.perdigao.Application - No Spring profile configured, running with default configuration<br> 
[DEBUG] org.portotech.perdigao.config.MailConfiguration - Configuring mail server<br> 
[INFO] org.portotech.perdigao.config.ThymeleafConfiguration - loading non-reloadable mail messages resources<br> 
[DEBUG] org.portotech.perdigao.config.DatabaseConfiguration - Configuring Mongeez<br> 
[DEBUG] org.portotech.perdigao.service.MailService - Send e-mail[multipart 'false' and html 'false'] to '[email protected]' with subject 'test' and content=test<br> 
[WARN] org.portotech.perdigao.service.MailService - E-mail could not be sent to user '[email protected]', exception is: Mail server connection failed; nested exception is javax.mail.MessagingException: Connection error (java.net.NoRouteToHostException: No route to host). Failed messages: javax.mail.MessagingException: Connection error (java.net.NoRouteToHostException: No route to host)<br> 
[INFO] org.portotech.perdigao.config.CacheConfiguration - Remove Cache Manager metrics<br> 
[INFO] org.portotech.perdigao.config.CacheConfiguration - Closing Cache Manager 

然后我再次执行,并且不会再得到了消息,有关的NoRouteToHostException,日志就像我发布的第一个日志。这真的很奇怪= /。无论如何,我做了一个ping smtp.gmail.com,并没有问题。

+0

如果失败,你应该有一个堆栈跟踪日志中,可以后呢? – 2014-10-27 19:39:55

+0

刚刚添加的信息,希望它可以帮助你,以帮助我:) – trufrgs 2014-10-27 23:04:46

回答

5

您正在使用端口25和TLS和TLS使用端口587

+0

谢谢,朱利安,但我也试过端口587,它仍然没有工作。 – trufrgs 2014-10-27 23:24:55

+1

当我尝试使用端口587向应用程序签名时,这是我得到的日志: [警告] org.portotech.perdigao.service.MailService - 电子邮件无法发送给用户'xxx @ gmail.com',例外是:邮件服务器连接失败;嵌套异常是javax.mail.MessagingException:获取欢迎信息时出错。失败的消息:javax.mail.MessagingException:获取欢迎信息时出错msg [DEBUG] org.portotech.perdigao.aop.logging.LoggingAspect - 退出:org.portotech.perdigao.service.MailService.sendActivationEmail()with result = null – trufrgs 2014-10-27 23:28:08

+3

经过一些尝试(也尝试了端口465)后,我发现需要更改配置以允许访问用于发送电子邮件的gmail帐户上不太安全的应用程序。无论如何,它有助于确保正确的端口是587.谢谢你的帮助。 – trufrgs 2014-10-28 00:21:59