Using Symfony Mailer to send emails

Silverstripe 4.10

How do I configure Symfony Mailer in Silverstripe 4.10.

I am new to Silverstripe and I am finding sending emails to be extremely complicated. It says to never use Swiftmailer so I installed Symfony Mailer using Composer. Unfortunately, I have no idea where to even start configuring it. I have read about email configuration in the Silverstripe Docs but they could not help me.
I know I am supposed to edit the file app/_config/email.yml

# See for additional information about setting up email
Name: project-emailconfig
  - '#emailconfig'
    class: Swift_SendmailTransport

How do I edit email.yml to be able to send emails using Symfony Mailer? Any other alternatives are welcome, I just want mail to work. This is my first question so I apologise if it is not properly formatted and would welcome a kind person to format it correctly.

Symphony mailer is installed in the root directory.

Hi kal,

I am not entirely sure why you would want to install Symfony Mailer, as it is not necessary. If you have any other reason why you would want to install the Symfony mailer, please state them and we‘ll restart from there :wink:)

If you refer to the following passage in the docs when you say it states „to never use Swiftmailer“:

For legacy reasons, Silverstripe CMS 4 defaults to using the built-in PHP mail() command via a deprecated class Swift_MailTransport . However, using this layer is less secure and is strongly discouraged.

Then you do not need to replace the entire library. The point is, that the Swift_MailTransport class has been deprecated because of a security issue. The other classes should still work fine and you can configure an alternative like Swift_SendmailTransport or Swift_SmtpTransport which are well described in the docs.

I hope this helps!

Hi mleutenegger,

I really appreciate your help. As for Symfony Mailer, I thought it would be good to start using the recommended library. Well I am used to Codeigniter and Laravel and find configuring email settings in Silverstripe complicated.The mail part is what is troubling me, I am alright with much of it, almost done with the lessons, I can’t thinkm of a better CMS even after playing with Processwire and ExpressionEngine, Syslverstripe’s phylosophy is in its own class.
I could use Swiftmail, I read that it has been abandoned and no longer being maintained. Could you help me with example configuration using the alternative class?
once again thanks.

Ah, in that case I have to apologize, this info did not yet make it through to me…

I now see why switching to the symfony mailer would be a good idea, but this is not something you can achieve with configuration only. Silverstripe uses swiftmailer under the hood with the SwiftMailer class, which relies on a Swift_Transport to actually send out mails. I found the corresponding Issue on the framework repo, so there is some solution-finding going on:

It also looks like currently, there is no valid way of injecting another mailer for silverstripe to use.

In any case, the mailer is just a wrapper around the system binary, so not switching away from swiftmailer at the current stage should not pose a huge risk to your application / page (:rotating_light: personal opinion), and the folks over at Silverstripe are already considering alternatives, likely being released at a later stage.