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 }
Related
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
Symfony seems to be unable to send confirmation mail, this is my code
I tried everything but no result.
This is the code of config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: BackOfficeBundle\Entity\User
service:
mailer: fos_user.mailer.twig_swift
registration:
confirmation:
enabled: true
from_email:
address: '%mailer_user%'
sender_name: '%mailer_user%'
from_email:
address: '%mailer_user%'
sender_name: '%mailer_user%'
This is the code of parameters.yml:
parameters:
database_host: 127.0.0.1
database_port: null
database_name: fos
database_user: root
database_password: null
mailer_transport: gmail
mailer_auth_mode: login
mailer_encryption: ssl
mailer_host: smtp.gmail.com
mailer_user: mail.mail#gmail.com
mailer_password: 000000
secret: ThisTokenIsNotSoSecretChangeIt
This is the code of config_dev.yml:
swiftmailer:
transport: gmail
username: '%mailer_user%'
password: '%mailer_password%'
The user is created and in description it said that i should check my email
Any suggestion is appreciated.
The issue probably comes from the fact that you're testing in a local environment without a valid certificate, thus you can't establish a secure connection to the Gmail server.
To make it work, try to:
Configure the Gmail account (it's preferable not to use your personal account) by creating an app password and allowing access to less secure apps, as described at the bottom of this page.
Add the verify_peer option set to false in the swiftmailer configuration:
#config_dev.yml
swiftmailer:
transport: gmail
username: '%mailer_user%'
password: '%mailer_password%'
stream_options:
ssl:
verify_peer: false
Note that this setup is not secure and should only be used in the dev
environment for quick tests without sensitive data. You should also add the delivery_addresses option in swiftmailer configuration to send all mails to one address.
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.
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.
I can't get the file spooling to work properly with Symfony 2 and Swiftmailer.
This is my config
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool:
type: file
path: '%kernel.root_dir%/spool'
port: %mailer_port%
encryption: %mailer_encryption%
sender_address: %mailer_sender_address%
When I send an email, a file is created in app/spool/default/
I then run
php app/console swiftmailer:spool:send
and get this response
[2015-12-29 18:54:40] Processing default mailer... 1 emails sent
So it looks like it has worked, but nothing is sent and /var/log/mail.log does not show any new emails.
When I had the config set to memory spooling, the emails were working without any issue, all I changed was config.yml
swiftmailer:
spool: { type: memory }
changed to
swiftmailer:
spool:
type: file
path: '%kernel.root_dir%/spool'
I'm using sendgrid and postfix to actually send out the emails, but I'm not sure that the emails are even getting to postfix, so that probably doesn't make any difference.
The problem ended up being the default environment. All I needed to do was specify an environment other than dev
php app/console swiftmailer:spool:send --env=prod