如何使用 Play Mailer 向多个收件人发送电子邮件并隐藏他们的地址

How to send an email to multiple recipients and hide their addresses using Play Mailer

我在 Scala 中使用 Play Mailer,我正试图将同一封电子邮件发送给多个收件人。有没有办法将我的电子邮件分别发送给多个收件人,这意味着收件人看不到其他收件人的地址?这是用于将同一封电子邮件发送到一系列电子邮件的代码,因此收件人可以在 TO 字段中看到所有其他地址。

import play.api.libs.mailer._
import java.io.File
import org.apache.commons.mail.EmailAttachment
import javax.inject.Inject
import play.api._
import play.api.mvc._
import scala.concurrent.Future
import play.api.libs.json._

class MailerApi @Inject() (mailerClient: MailerClient) extends Controller {
  def sendEmail = Action.async(parse.json) { request =>
    val subject: String = (request.body \ "subject").as[String]

    val cid = "1234"
    val email = Email(
      subject,
      "ExcelWay <email1@gmail.com>",
      Seq("Miss TO <email2@gmail.com>",<email3@gmail.com>),
      // adds attachment
      attachments = Seq(),
      // sends text, HTML or both...
      bodyText = Some("A text message"),
      bodyHtml = Some("content")
      )
    mailerClient.send(email)
    Future.successful(Ok("ok !!"))
  }
}

在他们不知道还有其他收件人的情况下向多个收件人发送邮件的最佳做法是向您自己发送电子邮件并将所有收件人添加为密件抄送。

将此添加到您的 Mail 对象中:

bcc = Seq("email1@domain.com", "email2@domain.com")

并使用您自己的邮件地址设置 TO 字段。