从本地主机发送电子邮件 - Play Framework
有谁知道需要在 Play Framework 项目的 application.conf
文件中应用的 smtp
设置,以便在本地主机上发送电子邮件?
在我的单元测试期间,我收到错误:
已捕获 play.exceptions.MailException,无法发送电子邮件
Play 的开发人员使发送电子邮件变得如此简单,以至于我可能搞砸的唯一方法就是配置文件中的设置。
我尝试过仅使用:
mail.smtp=mock
我尝试注释掉上面的行并使用:
mail.smtp.host=127.0.0.1
这两种方法都不起作用。我知道这可能是一个非常菜鸟的问题,但我以前从未真正处理过设置电子邮件 - 所以我很感激任何可以提供的帮助。
如果我无法发送电子邮件,因为 Play 无法作为 SMTP 服务器工作,有什么方法可以使用 mail.smtp=mock
来“模拟发送”电子邮件并允许我的测试通过吗?
有用的链接
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了更好地诊断问题,您可以使用以下设置(在 application.conf 中)来提供电子邮件发送过程的更多详细信息。
然而,出于测试目的,我发现使用 GMail 是发送电子邮件的最简单方法。
配置(同样在 application.conf 中)是...
有关所有配置的完整详细信息,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.
However, for testing purposes, I have found using GMail the easiest method for sending emails.
The configuration (again in application.conf) is...
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
我用的是1.2.4。 (尚未移植...)
play.mvc.Mailer.send() 可能失败的原因有多种,但是,如果您查看抛出的异常的第一级,则真正的原因会被抑制,因为抛出的是( play.mvc.Mailer.java:349):
play.exceptions.MailException 继承自 java.lang.RuntimeException。真正的异常 ex 被设置为原因。
我建议查看原因字段。示例:
这可能会打印出更有用的内容。
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):
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:
This may print out something more useful.
对于未来的开发人员,我在 Mac OSX 上使用 Play2.1,这是我要发送到本地主机的邮件配置...
使用 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...
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.