gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:40:52 24 4
gpt4 key购买 nike

我知道这可能是一个非常简单的问题,但我在这个问题上坚持了很多小时,在互联网上进行了大量研究后我没有发现问题。

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

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

../src/main/resources/config/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

然后我尝试进行新的注册并且没有进行邮件确认,我还尝试运行测试,从“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 '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 操作,没问题。

最佳答案

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

关于email - 在 JHipster (Spring) 项目上配置邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26593008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com