How to test email logic with Play Framework
Asked Answered
A

1

6

I got an class that extends Mailer and would like to have automatic tests for that.

With mock mailer I can get the mail to console but how to test mail logic from the automated test?

(Is there something like Mailer testing with Rails?)

br, Touko

Azaleah answered 8/5, 2012 at 12:44 Comment(0)
A
14

While writing this question, I found this link : Testing mail sending by using Mock Mailer.

So, one can access mails mailed with Mock mailer with play.libs.Mail.Mock as follows:

String email = Mail.Mock.getLastMessageReceivedBy("[email protected]");

The mail is returned as one string but that's better than nothing.

Though to share this since it took me a while to find this.

Azaleah answered 8/5, 2012 at 12:46 Comment(1)
Note that from Play Framework >= 1.3.0, you can use Mail.useMailSystem, more details e.g. github.com/playframework/play1/blob/…Azaleah

© 2022 - 2024 — McMap. All rights reserved.