简体   繁体   English

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

[英]Configuring mail on JHipster (Spring) project

I know it must be, probably, a very simple question, but I'm stucked at this for many hours I didn't find the problem after lots of research on internet. 我知道这可能是一个非常简单的问题,但我已经坚持了好几个小时,经过大量的互联网研究后我没有发现问题。

I started a jhipster project, and now I'm trying to configure a e-mail server to use for send registration e-mails to my new users. 我开始了一个jhipster项目,现在我正在尝试配置一个电子邮件服务器,用于向我的新用户发送注册电子邮件。 So I edited the 2 configuration files that exist in the project: 所以我编辑了项目中存在的2个配置文件:

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

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

In each one of these I added the following lines under "Spring: mail:" 在其中的每一个中,我在“Spring:mail:”下添加了以下行:

    host: smtp.gmail.com
    port: 25
    user: xxx@gmail.com
    password: xxx
    protocol: smtp
    tls: true
    auth: true
    from: xxx@gmail.com

Then I tried to make a new registration and didn't work the mail confirmation, I also tried to run a test, calling explicitly the function "sendEmail" from the "mailService", it also didn't work. 然后我尝试进行新的注册并且没有工作邮件确认,我也尝试运行测试,从“mailService”显式调用函数“sendEmail”,它也没有用。 Someone knows why? 有人知道为什么吗? Am I making some configuration mistake? 我是否犯了一些配置错误? There is something else I should make? 还有什么我应该做的?

Adding the asked info about logs: 添加有关日志的询问信息:

Usually this is the log that I get when I run the test which calls the sendMail function: 通常这是我运行调用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

So, the email wasn't sent, but I got no error message. 所以,电子邮件没有发送,但我没有收到任何错误消息。 After you posted the comment, I opened my IDE again (Intellij) to copy the log to post here and got the following log: 在您发布评论后,我再次打开我的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

Then I executed again, and never got that message again, about the NoRouteToHostException, the log is like the first I posted. 然后我再次执行,并且再次没有得到关于NoRouteToHostException的消息,日志就像我发布的第一个。 That's really weird =/. 这真的很奇怪= /。 Anyway, i did a ping to smtp.gmail.com and it is ok. 无论如何,我对smtp.gmail.com进行了ping操作,这没关系。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM