SwiftMailer how to configure it with google? - symfony

I have installed sendmail and it's work's with gmail so it's not a problem.
In swift mailer config yaml it's looks like:
swiftmailer:
transport: smtp
encryption: tls
auth_mode: login
host: smtp.gmail.com
username: (this is my email)
password: (this is my pass)
port: 587
in .env:
MAILER_URL=gmail://username:password#localhost
I get this error:
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
I don't know because if i use mail function it's work's fine.

Related

Swiftmailer does not send from Hyper-V virtual machine

A Hyper-V machine with Ubuntu 18 has a Symfony 4.3 app with SwiftMailer. Attempts to send an email from the command line with php bin/console swiftmailer:email:send result in
[OK] 1 emails were successfully sent.
although mail.log contains this
localhost sm-mta[5847]: xBBFThub005847: localhost [127.0.0.1] did not
issue MAIL/EXPN/VRFY/ETRN during connection to MTA-v4
and the email is never received.
.env.local contains
MAILER_URL=gmail://username#gmail.com:password#localhost?encryption=tls&auth_mode=oauth
.../config/packages/swiftmailer.yaml:
swiftmailer:
default_mailer: memory
mailers:
memory:
sender_address: 'admin#bogus.info'
transport: smtp
spool: { type: 'memory' }
spooler:
sender_address: 'admin#bogus.info'
transport: smtp
spool:
type: file
path: '%kernel.project_dir%/var/spool'
Using the identical configuration from the host DOES deliver mail.
While the eventual solution may be excessive it is effective. I first tried installing sendmail but that went nowhere. Purged it and installed postfix following this tutorial on using postfix to relay to gmail. When a test message failed I followed the answer provide by kjones at this site. Allowed "Access for less secure apps setting" at gmail and all is now well.
All this for a practice go-live run!

Problem with sending emails in Heroku using Swiftmailer

I wrote an application in symfony 4.
I deployed it on the heroku.
Everything works as it should with the exception of sending emails.
When I trying to send an e-mail from the console like this:
heroku run php bin/console swiftmailer:email:Send
Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "healthcard95#gmail.com" using 1 possible authenticat
ors. Authenticator LOGIN returned Swift_TransportException: Expected response code 235
Please log in via your web browser and then try again.
Learn more at https://support.google.com/mail/answer/78754 i65sm11848023qkh.49 - gsmtp
" in /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457
This is my swiftmailer.yaml file:
swiftmailer:
transport: gmail
username: username
password: ********
host: localhost
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
How to fix this error?
The problem is in Gmail.
Although I have set up security to allow less secure applications and e-mails from local hosts are sent correctly when I perform the same operation in gmail heroku, I see a new device - unfortunately I can't add it to trusted devices, therefore it's blocked.
The solution was to change mail, e.g. on yandex.com.
Here is an example file swiftmailer.yaml correctly configured for heroku:
swiftmailer:
transport: smtp
username: username
password: ********
host: smtp.yandex.com
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false

How can I send emails using Symfony, Swift Mailer, and Office 365?

I'm using Symfony 3.4 deployed in HostGator. I need send emails to my users in some cases. If I use Gmail, the emails are sent without problem, but when I use Office 365, I'm getting the following error:
Connection could not be established with host
This is my email configuration:
parameters:
mailer_transport: smtp
mailer_host: ''
mailer_user: example#mydomain.co
mailer_password: 'mypassword'
mailer_port: '587'
mailer_smtp: 'smtp.office365.com'
I would try pasting the 'smtp.office365.com' for the field: mailer_host
Use host instead of mailer_smtp. I have this configuration for my swiftmailer. Hope it works for you.
# Swiftmailer Configuration
swiftmailer:
transport: 'smtp'
host: '%mailer_host%' // in your case : 'smtp.office365.com'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }

Email Sent But Not Receiving with swiftMailer

I am facing issue in Symfony Swiftmailer to send mail.
By Using command:
php app/console swiftmailer:email:send
and this is my swiftMailer.yaml
swiftmailer:
transport: gmail
username: "**************#*******"
password: "****************"
host: smtp.gmail.com
port: 465
encryption: ~
auth_mode: ~
sender_address: ~
antiflood:
threshold: 99
sleep: 0
delivery_addresses: ~
disable_delivery: ~
logging: true
is there anyone know what is the problem ?
If your Gmail account uses 2-Step-Verification, you must generate an App password and use it as the value of the mailer password. You must also ensure that you allow less secure apps to access your Gmail account.

"Connection could not be established with host smtp.gmail.com". Symfony. Swiftmailer

I got exception:
Connection could not be established with host smtp.gmail.com
Same exception in old project Symfony2.8 and newest Symfony3.
I can ping smtp.gmail.com.
The Avast Antivirus was guilty.
In Google "Account settings" enable "Access for less secured apps" by setting it to "Allow".
Mailer host is your localhost or 127.0.0.1. It's not smtp.google.com
I'm using this configuration for my localhost application
parameters:
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: youremail#gmail.com //replace by your gmail account
mailer_password: ********** //replace by your gmail password
config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
your controller code seems to be the same as mine.
As napestershine said in his response do not forget to allow less secure app on your gmail account.

Resources