Configure SwiftMailer To Use Yahoo! Mail

in php •  4 years ago 

My ISP has been blocking SMTP (port 25 and 456), making it difficult for me to test email notifications in application, especially when you use Sendmail for sending emails. So I reconfigured my application to use my Yahoo mail account, and it is not as straight forward as I think...

Enable Less Secured App Access

By default, Yahoo does not allow 3rd party client access. Head over to https://login.yahoo.com/myaccount/security/?.scrumb=lKUdk7JUldB and generate an application password. This password allows your application to access Yahoo SMTP server.

Configure SwiftMailer

$transport = (new Swift_SmtpTransport('smtp.mail.yahoo.com', 587, 'tls'))
    ->setUsername('[email protected]')
    ->setPassword('application-password');

$mailer = new Swift_Mailer($transport);

$message = (new Swift_Message('Test from ' . gethostname() . ' at ' . date('r')))
    ->setFrom(['[email protected]' => 'Hong'])
    ->setTo(['[email protected]'])
    ->setBody('Testing Yahoo SMTP server');

$result = $mailer->send($message);  

IMPORTANT NOTE

  • Use port 587 to avoid blocking by ISP
  • Always use TLS encryption with port 587
  • The username and FROM header MUST be your Yahoo email address.
  • Use the generated application password, instead of your mail account password.

Google SMTP

Configuration for Google is also similar. You must first enable less secure app access. Then generate password for your application.

Similarly, use TLS encryption with port 587. Username must be your GMail address.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...