Send Email Via Gmail SwiftMailer Symfony2 - symfony

I'm trying to send email with swiftmailer via commande but i got this error message
the commande :
php app/console swiftmailer:email:send
The error:
Connection could not be established with host smtp.gmail.com
Why is that's ?
My configuration parameters.yml file looks like this :
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: my gmail
mailer_password: my password
secret: secret

You can try with this:
#app/config/parameters.yml
parameters:
# ...
mailer_transport: gmail
mailer_host: ~
mailer_user: your_gmail_username
mailer_password: your_gmail_password

Configure your SwiftMailer(config.yml):
swiftmailer:
transport: %mailer_transport%
encryption: ssl
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }

Related

send mail with gmail in symfony

I want to send emails with the swiftmailer and gmail in a symfony 3.4 project, but I succeeded in local but not in prod.
parameters.yml
database_host: server_bdd_ovh
database_port:
database_name: trexfastjjtrex
database_user: database uder
database_password: password database
mailer_transport: gmail
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_port: 587
mailer_user: address#gmail.com
mailer_password: password
mailer_prod_encryption: tls
administrateur_contact_mail: address#gmail.com
webmaster_contact_mail: address#gmail.com
payee_email: null
config.yml
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
auth_mode: "%mailer_auth_mode%"
host: '%mailer_host%'
port: "%mailer_port%"
username: '%mailer_user%'
password: '%mailer_password%'
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
Locally it works but not in prod are there configurations to do
Thanks for your help

mailer does not work on prod with the same settings as on dev

Basically after changing from Dev to Prod on Symfony, the mailer stopped sending mails to given email.
Posting few settings from my Symfony:
parameters:
mailer_transport: smtp
mailer_port: 465
mailer_host: myhost
mailer_user: mylogin
mailer_password: mypw
config:
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
port: '%mailer_port%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
logging: true
# delivery_addresses: ['']
It looks correctly for me. The website uses SSL if that matters. Is there anything to change/edit? Do you need any other code to assist me with?

Configuration to send Email with Symfony herberged on OVH

I am trying to send email with my Symfony Application. My goal is to send the emails either with a gmail account or from the server's email account.
After some research I succed to send emails from my local server wamp. The configuration is the following :
swiftmailer:
transport: %mailer_transport%
encryption: %mailer_encryption%
auth_mode: %mailer_auth_mode%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
mailer_transport: smtp
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_transport: gmail
mailer_user: myaccount
mailer_password: mypassword
I tried this configuration on my OVH server but it doesn't work. I looked in the OVH server logs but didn't find any error message.
I also tried some configuration with my server email account from my local server WAMP without success.
Here is one example :
swiftmailer:
transport: %mailer_transport%
auth_mode: %mailer_auth_mode%
host: %mailer_host%
port: %mailer_port%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
mailer_transport: smtp
mailer_auth_mode: login
mailer_host: smtp.mydomain.be
mailer_port: 587
mailer_user: admin#mydomain.be
mailer_password: mypassword2
The solution is to set your mailer_transport parameter to 'mail' so SwiftMailer will use the default PHP mail() function.
Otherwise, you could specify the transport directly from your controller:
// Mail() transport
$transport = \Swift_MailTransport::newInstance();
// Message
$message = \Swift_Message::newInstance()
->setFrom("me#domain.org", "My Name")
->setTo(array(
"user#domain.org" => "User Name"
))
->setSubject("Solution for sending e-mail from OVH")
->setBody("...", 'text/plain')
;
// My instance of mailer
$mailer = \Swift_Mailer::newInstance($transport)
->send($message);
Worked for me on an OVH plan with shared e-mail.

During send email using gmail in Symfony2 error occured

I have problem to send email using gmail. When I tested form on my server mailer works ok but after moved website to another provider error ocured
INFO - Matched route "my_frontend_default_index" (parameters: "_controller": "My\FrontendBundle\Controller\DefaultController::indexAction", "_route": "my_frontend_default_index")
ERROR - Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "tomasz.zalewski01#gmail.com" using 1 possible authenticators
my parameters.yml
parameters:
mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'tomasz.zalewski01#gmail.com'
my config.yml
swiftmailer:
transport: gmail
host: smtp.gmail.com
username: 'tomasz.zalewski01#gmail.com'
password: 'password'
Someone have idea where is the problem ?
First of all why are you not using your parameter keys in your config? You shouldnt need to touch the config at all. Leave it as:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
port: %mailer_port%
encryption: %mailer_encrypt%
Then for your parameters.yml use:
parameters:
# ...
mailer_transport: gmail
mailer_host: ~
mailer_user: your_gmail_username
mailer_password: your_gmail_password
mailer_port: 465
As suggested in http://symfony.com/doc/current/cookbook/email/gmail.html

Symfony Send email in production environment

I am trying to send email in prod environment but it doesn't work... I am getting this log:
[2014-06-30 09:37:54] request.CRITICAL: Uncaught PHP Exception
Swift_TransportException: "Expected response code 250 but got code
"530", with message "530 5.7.0 Must issue a STARTTLS command first.
o2sm28357522wia.16 - gsmtp "" at
C:\xampp\htdocs\UniDocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php
line 386 {"exception":"[object] (Swift_TransportException: Expected
response code 250 but got code \"530\", with message \"530 5.7.0 Must
issue a STARTTLS command first. o2sm28357522wia.16 - gsmtp\r\n\" at
C:\xampp\htdocs\UniDocs\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php:386)"}
[]
However, in dev it is working...
The config I have is the following:
config_dev.yml:
swiftmailer:
transport: smtp
encryption: ssl
auth_mode: login
host: smtp.gmail.com
username: myemail#gmail.com
password: mypass
config.yml:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
parameters.yml:
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: myemail#gmail.com
mailer_password: mypass
I also have another question..., in web/app.php do I have to write $kernel = new AppKernel('prod', false); or $kernel = new AppKernel('prod', true);??
I've used my Gmail account to send emails in Symfony2, and I specify some parameters which you have not specified. Below is my configuration:
config.yml:
swiftmailer:
transport: %mailer_transport%
encryption: %mailer_encryption%
auth_mode: %mailer_auth_mode%
host: %mailer_host%
username: %mailer_username%
password: %mailer_password%
spool: { type: memory }
parameters.yml:
mailer_transport: smtp
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_username: myusername#gmail.com
mailer_password: mypassword
Related with your second question, the original line is
$kernel = new AppKernel('prod', false);
If you change this to true, error messages can be showed in production mode, because the second parameter of the AppKernel construct indicates the debug mode.

Resources