Search code examples
pluginsplayframeworkmailer

Play Framework [play-mailer]: how to ensure each receiver sees only his or her email address in the TO field


Here below is the code to send an email with play-mailer:

import play.api.libs.mailer._
...

val email = Email(
  "My Subject",
  "Me <[email protected]>",
  Seq("[email protected]", "[email protected]", "[email protected]"),
  bodyText = Some("Some text..."),
  bodyHtml = Some("<p>Some text...</p>")
)
MailerPlugin.send(email)

The problem is that receivers see all the recipients the email was sent to. Of course, an option could be to invoke MailerPlugin.send for every single recipient... but I'm wondering if there is a better way to ensure each receiver sees only his or her email address in the to field.


Solution

  • Perhaps the best solution will be using hidden recepient which aka BCC. Emailer plugin has method addBcc(String address):

     public void addBcc(String address) {
        this.bcc.add(address);
      }
    

    Regards!