SwiftMailer without $app->mailer?

Simple question: Would there be any problem with using the SwiftMailer in it’s plain PHP form, per https://swiftmailer.symfony.com/docs/introduction.html, rather than going through the Yii::$app->mailer object?

Larger question: The reason I want to do this is that my app sends email through the Google SMTP server with the organization’s username and password. The organization recently changed the password, so course the email has stopped working until I update the password in \config\web.php. But I’m thinking it would be friendly for them if I could provide a screen to allow them to change it themselves in my app whenever they change it there. I don’t want to rely on them telling me the password every time, and it might be too technical for them to update it in the web.php file themselves. I’m thinking I’d store the password in a hashed password field in the app’s MySQL database. So that’s why I think I need to bypass $app->mailer and use Swift’s transport object directly, with its setUsername and setPassword methods, since I don’t see any way in Yii’s object to set the password programatically.

Bad idea? Okay idea? Potential problems? Thanks for any advice.

No, it should be fine. Yii just provides convenience layer.

1 Like