Unable to send mail via gmail in Symfony 2.8.3 in prod on freebsd host while it works on Windows 10 with same source code in both prod & dev. [Also unable to get a log of mailing on host, which might help resolve this.]
Update: Mail can be sent using PHP's mail() function. Using Swiftmailer to send mail from a controller does not work. Changed parameters to use mailer_transport: smtp mailer_host: localhost does not enable Swiftmailer to send from a controller.
parameters.yml:
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: {valid address}
mailer_password: (valid password}
config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
encryption: ssl
auth_mode: login
config_prod.yml:
monolog:
handlers:
mail:
type: fingers_crossed
action_level: critical
handler: buffered
buffered:
type: buffer
handler: swift
swift:
type: swift_mailer
from_email: "%mailer_user%"
to_email: "%mailer_user%"
subject: Error report!
level: debug
In the absence of any other solution or finding a way to log Swiftmailer behavior I added a custom exception listener to send mail locally.
Related
I have the following code to send mails:
/* Emails */
$message = \Swift_Message::newInstance()
->setSubject('Ihre Sammelrechnung')
->setFrom("xxx#myserver.com")
->setTo("recipient#gmail.com")
->setBody(
$this->renderView(
'email/invoiceMultiFinal.html.twig', array(
'company' => 'COMPANY',
)
),
'text/html'
);
/* Send eMail */
if(!$this->get('mailer')->send($message)){
die("ERROR");
}
I know 100% that sender an recipient are correct. In my Logs I have:
{"message":"Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username \"xxx#myserver.com\" using 1 possible authenticators","context":[],"level":400,"level_name":"ERROR","channel":"app","datetime":{"date":"2016-05-31 15:19:09.919207","timezone_type":3,"timezone":"Europe/Berlin"},"extra":[]}
config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory } #Deleting this changes nothing
parameters.yml
parameters:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: xxx#myserver.com # adding "" doesn't change sth either
mailer_password: password
secret: xxxxxxx
I am using my own server, so no Gmail etc. involved. I can send and receive emails through the webmailer AND through php bin/console swiftmailer:email:send
Any ideas what can cause such behaviour? Side note, it worked like a charm for almost a month! It stopped today, possibly related to a reboot!
i'm trying to do my first symfony project and i am using the fosuserbundle. It's working perfectly i'm just having a problem with the email confirmation, i'm not receiving anything.
This is my parameters.yml:
parameters:
database_host: 127.0.0.1
database_port: null
database_name: mydatabase
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: mymail#gmail.com
mailer_password: mypass
secret: 8c73d1f9bc7f50ce500d4a98a4627ffaa42dc905
this is myconfig.yml:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
port: "585"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: OC\UserBundle\Entity\User
service:
mailer: fos_user.mailer.twig_swift
registration:
confirmation:
enabled: true
from_email:
address: mymail#gmail.com
sender_name: myname
service:
mailer: fos_user.mailer.twig_swift
please can you help? because i searched on the web and tried but since it's my first project none of the solutions are working with me.
Try with these slight changes in your config.yml:
port: 585
auth_mod: login
The value for the port doesn't need to be enclosed in quotes. I'm not sure if this really makes a difference, but you should follow the conventions.
Since you're using smtp as mailer_transport you have also to specify the authentication mode. Check the documentation for more details:
http://symfony.com/doc/current/reference/configuration/swiftmailer.html
Eventually you'll need another value for the authentication mode.
EDIT (2016-02-19):
Instead of using smtp as mailer_transport you can use the shortcut gmail. Please see this article from the Symfony Cookbook:
http://symfony.com/doc/current/cookbook/email/gmail.html
Then you can omit the line:
auth_mod: login
This shortcut will set the host to smtp.gmail.com. In your configuration you have the host set to 127.0.0.1. This could eventually be the reason why it works with the web_profiler, but not with the real e-mail address.
I got a strange behavior when sending email using Swiftmailer
here is the paramaters:
#Swiftmailer parameters # app/config/parameters.yml
parameters:
mailer_transport: smtp
mailer_host: ssl0.ovh.net
mailer_user: my_account#my_domain.com
mailer_password: my_account_password
mailer_port: 465
auth_mode: plain
encryption: ssl
the config
# Swiftmailer Configuration # app/config/config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
port: "%mailer_port%"
encryption: "%encryption%"
auth_mode: "%auth_mode%"
Now the controller and the action
class MailTestController extends Controller
{
public function SymfonyParamatersAction()
{
$message=\Swift_Message::newInstance()
->setSubject('smtp test with sm params')
->setFrom('my_account#my_domain.com')
->setTo('my_account#gmail.com')
->setBody('this is a test')
;
$result =$this->get('mailer')->send($message);
dump($this->get('mailer')->getTransport());die;
//return $this->render('...');;
}
}
So in the profiler I got one email sent but I dont receive any mail
I added this action to my controller
public function DirectParamatersAction()
{
$transport = \Swift_SmtpTransport::newInstance('ssl0.ovh.net', 465,'ssl')
->setUsername('my_account#my_domain.com')
->setPassword('my_account_password')
;
$transport->start();
$mailer = \Swift_Mailer::newInstance($transport);
$message=\Swift_Message::newInstance()
->setSubject('smtp test with direct params')
->setFrom('my_account#my_domain.com')
->setTo('my_account#gmail.com')
->setBody('this is a test')
;
$result =$mailer->send($message);
dump($transport);die;
return $this->render('.........');
}
with this action I received the message
the funny part (strange behavior) is when running these actions, I get different result:
1=> message is sent
2=> Expected response code 250 but got code "235", with message "235 ok, go ahead (#2.0.0)
3=>Connection could not be established with host ssl0.ovh.net [Connection timed out #110]
I clean the cache every time I change the config
I have to reload the page again and again to send the message
my question is what is wrong with the parameters and the first action?
secondly how to avoid this strange behavior?
the problem was in old configuration in app/conf/config_dev.yml
I having trouble send bulk emails with symfony2 via console command. I want to disable the mail spooling complete for the env the console is running in but keep it working for the default env. So I have this in config.yml:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
port: %mailer_port%
username: %mailer_user%
password: %mailer_password%
spool: %mailer_spool_type%
and then each env has it's on parameters like parameters_prod.yml:
parameters:
mailer_transport: smtp
mailer_host: smtp.someserver.net
mailer_port: 587
mailer_user: "someuser"
mailer_password: "somepassword"
mailer_spool_type: { type:memory }
then for the console env I use parameters_cron.yml:
parameters:
mailer_spool_type: ~
The problem is using ~ or null doesn't actually turn off the spool but it uses the default values of {cache: file, path: %kernel.cache_dir%/swiftmailer/spool }
Is there a way to disable the spool just by changing the parameters or is there a better way?
Apparently the only way to disable email spooling is to completely leave out the spool entry from your configuration file. Once you include the spool entry in the main configuration file, there is no way to disable spooling for a specific environment.
That said, you can accomplish the opposite of what you propose: you can disable email spooling by default and enable it in specific environments.
Leave it out in config.yml:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
port: %mailer_port%
username: %mailer_user%
password: %mailer_password%
And include it in config_prod.yml:
swiftmailer:
spool: %mailer_spool_type%
$mail = \Swift_Message::newInstance()
->setSubject($message->getSubject())
->setFrom($message->getEmail())
->setBody($message->getBody());
$this->get('mailer')->send($mail);
Mails are not sent when using swiftmailer. Yet, when I go step by step in the debugger, it seems to send the email and returns sent=1. However I don't receive anything in my mailbox (gmail). I use my gmail account for sending emails, as shown below:
parameters:
mailer_transport: gmail
mailer_host: ~
mailer_user: username#gmail.com
mailer_password: my-password
delivery_address: username#gmail.com
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
I've checked apache error log, nothing. I've run php app/console swiftmailer:spool:send just in case, but no luck.
What could prevent emails from being sent ?
You need either to:
1) Remove the spool line in your swiftmailer configuration, this one:
spool: { type: memory }
2) Trigger the spool queue to be sent:
php app/console swiftmailer:spool:send
But I think you are looking for option 1)
u can try this one...
Parameter.yml
mailer_transport: gmail
mailer_encryption: ssl
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: 'xxxxxxxxxxxx'
config.yml
swiftmailer:
transport: gmail
host: smtp.gmail.com
username: 'Yourmail-id#gmail.com'
password: 'Password'
The ->setTo part was missing ! That solved it.
$mail = \Swift_Message::newInstance()
->setSubject($message->getSubject())
->setFrom($message->getEmail())
->setTo("me#gmail.com")
->setBody($message->getBody());
First, when you set spool: { type: memory } it means that you actually want to send the emails manually by running the spool command: php app/console swiftmailer:spool:send. So removing that spool line is going to help.
Second, you need to properly configure your mailing host. For development purposes, I strongly recommend that you use a service such as SendGrid and configure it as detailed in this Symfony2 Mailing Setup Tutorial
The tutorial also contains details on how to properly setup a mailing service in Symfony2 and how to build mailing templates.
Third, if you want to stick with Gmail, then the correct data is:
mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_user: your_gmail_address#gmail.com
mailer_password: 'your_gmail_password'
mailer_port: 587