从本地主机发送电子邮件 - Play Framework

发布于 2024-11-30 20:06:52 字数 741 浏览 0 评论 0原文

有谁知道需要在 Play Framework 项目的 application.conf 文件中应用的 smtp 设置,以便在本地主机上发送电子邮件?

在我的单元测试期间,我收到错误:

已捕获 play.exceptions.MailException,无法发送电子邮件

Play 的开发人员使发送电子邮件变得如此简单,以至于我可能搞砸的唯一方法就是配置文件中的设置。

我尝试过仅使用:

mail.smtp=mock

我尝试注释掉上面的行并使用:

mail.smtp.host=127.0.0.1

这两种方法都不起作用。我知道这可能是一个非常菜鸟的问题,但我以前从未真正处理过设置电子邮件 - 所以我很感激任何可以提供的帮助。

如果我无法发送电子邮件,因为 Play 无法作为 SMTP 服务器工作,有什么方法可以使用 mail.smtp=mock 来“模拟发送”电子邮件并允许我的测试通过吗?

有用的链接

这是 Play 文档的链接发送电子邮件

Does anybody know the smtp settings that need to be applied within the application.conf file of a Play Framework project for sending emails on localhost?

During my unit testing I am getting the error:

A play.exceptions.MailException has been caught, Cannot send email

The developers at Play have made sending emails so easy that the only way I could be messing up is with my settings in the config file.

I have tried just using:

mail.smtp=mock

And I tried commenting out the line above and using:

mail.smtp.host=127.0.0.1

Neither of these two approaches work. I understand that this is probably a very noob question, but I have never really dealt with setting up emails before - so I am grateful for any help that can be contributed.

If it is the case that I am unable to send email as Play would not work as an SMTP server, is there any way that I can use mail.smtp=mock to 'mock send' an email and allow my tests to pass?

Useful Link

This is a link to the Play documentation for sending emails

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑白记忆 2024-12-07 20:06:52

为了更好地诊断问题,您可以使用以下设置(在 application.conf 中)来提供电子邮件发送过程的更多详细信息。

mail.debug=true

然而,出于测试目的,我发现使用 GMail 是发送电子邮件的最简单方法。
配置(同样在 application.conf 中)是...

mail.smtp.host=smtp.gmail.com
mail.smtp.user=yourGmailLogin
mail.smtp.pass=yourGmailPassword
mail.smtp.channel=ssl

有关所有配置的完整详细信息,Play Framework 页面提供了大量有关如何执行此操作的信息。

http://www.playframework.org/documentation/1.2.2/emails

To better diagnose the problem, you can use the following setting (in application.conf) to give more details of the email sending process.

mail.debug=true

However, for testing purposes, I have found using GMail the easiest method for sending emails.
The configuration (again in application.conf) is...

mail.smtp.host=smtp.gmail.com
mail.smtp.user=yourGmailLogin
mail.smtp.pass=yourGmailPassword
mail.smtp.channel=ssl

For full details of all the configurations, the Play Framework page has lots of information on how to do this.

http://www.playframework.org/documentation/1.2.2/emails

御弟哥哥 2024-12-07 20:06:52

我用的是1.2.4。 (尚未移植...)

play.mvc.Mailer.send() 可能失败的原因有多种,但是,如果您查看抛出的异常的第一级,则真正的原因会被抑制,因为抛出的是( play.mvc.Mailer.java:349):

throw new MailException("Cannot send email", ex);

play.exceptions.MailException 继承自 java.lang.RuntimeException。真正的异常 ex 被设置为原因。

我建议查看原因字段。示例:

try {
    Future<Boolean> future = play.mvc.Mailer.send(...);
} catch(MailException me) {
    System.out.println(me.getCause().getMessage());
}

这可能会打印出更有用的内容。

I use 1.2.4. (haven't ported yet...)

There are various reasons why play.mvc.Mailer.send() may fail, however the true reason is suppressed if you look at the first level of the exception thrown since what gets thrown is (play.mvc.Mailer.java:349):

throw new MailException("Cannot send email", ex);

play.exceptions.MailException inherits from java.lang.RuntimeException. The real exception, ex, is set as the cause.

I'd recommend taking a look at the cause field. Example:

try {
    Future<Boolean> future = play.mvc.Mailer.send(...);
} catch(MailException me) {
    System.out.println(me.getCause().getMessage());
}

This may print out something more useful.

筑梦 2024-12-07 20:06:52

对于未来的开发人员,我在 Mac OSX 上使用 Play2.1,这是我要发送到本地主机的邮件配置...

 host=localhost
 port=1025
 user="root@localhost" 
 from="root@localhost"

使用 Mac 商店中提供的 MockSMTP 应用程序 http://mocksmtpapp.com/

还使用类型安全插件

https://github.com/typesafehub/play-plugins/tree/master/mailer

我希望这可以帮助将来的人。

For future developers I use Play2.1 on Mac OSX, this is my mail configuration to send to localhost...

 host=localhost
 port=1025
 user="root@localhost" 
 from="root@localhost"

using MockSMTP application available at the Mac store http://mocksmtpapp.com/

Also using typesafe plugin

https://github.com/typesafehub/play-plugins/tree/master/mailer

I hope this can help someone in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文