在JHipster(Spring)项目上配置邮件

时间:2014-10-27 17:13:02

标签: email jhipster

我知道这可能是一个非常简单的问题,但我已经坚持了好几个小时,经过大量的互联网研究后我没有发现问题。

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

../的src /测试/资源/配置/ application.yml

../的src /主/资源/配置/ application.yml

在其中的每一个中,我在" Spring:mail:"

下添加了以下行:
    host: smtp.gmail.com
    port: 25
    user: xxx@gmail.com
    password: xxx
    protocol: smtp
    tls: true
    auth: true
    from: xxx@gmail.com

然后我尝试进行新的注册并且没有完成邮件确认工作,我还尝试运行测试,明确调用函数" sendEmail"来自" mailService",它也没有用。有人知道为什么吗?我是否犯了一些配置错误?还有什么我应该做的吗?

添加有关日志的询问信息:

通常这是我运行调用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 'xxx@gmail.com' 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 'xxx@gmail.com' with subject 'test' and content=test<br>
[WARN] org.portotech.perdigao.service.MailService - E-mail could not be sent to user 'xxx@gmail.com', 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的消息,日志就像我发布的第一个。这真的很奇怪= /。无论如何,我对smtp.gmail.com进行了ping操作,没问题。

1 个答案:

答案 0 :(得分:6)

您正在使用端口25和TLS,而TLS使用端口587。