Sending Mail Using DKIM Signing

I know how to send an e-mail with SwiftMailer using yii2 and non-yii2 classes. I have also used non-yii2 classes to sign the e-mail with a DKIM signature. However, I am struggling with doing this within Yii2.


$signer = new \Swift_Signers_DKIMSigner($dkim_private_key, $dkim_domain, $dkim_selector);


Yii::$app->mailer->compose($view, $params)

                 ->setFrom([$from_email => $from_name])

                 ->setTo($to_email)

                 ->setSubject($subject)

                 ->send();

I’m struggling with how to get proper SwiftMailer signing class included and how to integrate it into the code above.

If this is not possible, I can use my non-yii2 code to create a signed e-mail, but how do I get the e-mail body from the view file merged with the parameters the same way mailer->compose($view, $params) does?

Sample code would be an wonderful help!

Thanks

Do you have to do it via PHP? Your mail server could be configured so sendmail will sign all outgoing emails automatically.

I’m unsure that is possible since I’m on a hosted server, but I can check into it. However, since I can already do it in straight PHP, I thought it would be an easy step to do it within Yii2. Might be mistaken. If it is possible, I’d still appreciate help.

Have you tried the following?




$message->getSwiftMessage()->attachSigner($signer);



But how is $message defined? I would need a full code sample to accomplish what I need. I need to create the signer, message, get the message from the mail view file, merge with the needed data parameters, address and send it.

I can do all this in basic PHP and some in Yii2, but not all of it in Yii2.

Thanks




$signer = new \Swift_Signers_DKIMSigner($dkim_private_key, $dkim_domain, $dkim_selector);


$message = Yii::$app->mailer->compose($view, $params)

                 ->setFrom([$from_email => $from_name])

                 ->setTo($to_email)

                 ->setSubject($subject);


$message->getSwiftMessage()->attachSigner($signer);

$message->send();



I had it so close. Thank you very much!