playframework / playframework/play-mailer
Testing that an email is sent
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 252
- Forks
- 73
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 19
Description
Is there a way to test that an email is sent, and check the contents of it? Would be nice to do something like:
"A verification email is sent when the user has registered" in {
MailPlugin.startCapturing()
UserModule.registerNewUser(name = "Frodo", email = "frodo@example.com")
val emails: List[Email] = MailPlugin.stopCapturingAndCollectResults()
emails mustEqual List(
Email(
subject = "Welcome Frodo",
recipient = "frodo@example.com",
bodyText = "Here is your verifcation link: ______"
)
)
}
Or perhaps something more "functional"/safe:
"A verification email is sent when the user has registered" in {
val emails: List[Email] = MailPlugin.captureMailsSentInBlock {
UserModule.registerNewUser(name = "Frodo", email = "frodo@example.com")
}
emails mustEqual List(
Email(
subject = "Welcome Frodo",
recipient = "frodo@example.com",
bodyText = "Here is your verifcation link: ______"
)
)
}
Is it possible to do something like this at all right now? ie. Setting the plugin in testing/capture mode so that we can verify: (1) that en email is sent, (2) verify the contents of it.
Also, mock-mode must be on when running your test suite, right? (play.mailer.mock = yes)
I'm sorry if this is asked before, but I couldn't find anything in the manual or from searching.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the MailPlugin API and the play.mailer.mock configuration mentioned in the issue. Determine how test-mode mail delivery currently works and define a supported way to capture sent emails, inspect their subject, recipients, and body, and verify that behavior in tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100