Cannot get sendmail to work with Swiftmailer Bundle on Windows - php

I have the following setup/parameters:
PHP 7.1.26
Windows 10 x64 Professional
symfony/swiftmailer-bundle 3.5.2
symfony/console 4.1.11
I want to configure the swiftmailer-bundle to use the fake sendmail, which is installed at
C:\Program Files (x86)\sendmail
While I have already configured the sendmail_path in PHP, the swiftmailer-bundle does not actually use this PHP variable at all. Instead it defaults the path to the sendmail executable to
/usr/sbin/sendmail -bs
However, since version 3.0.4, the path (i.e. complete command) should be configurable: https://github.com/symfony/swiftmailer-bundle/pull/185
I put
swiftmailer:
mailers:
default:
transport: sendmail
command: 'C:\Program Files (x86)\sendmail\sendmail.exe -t'
into my app/config/config.yml and rebuilt the cache. However, when I want to send a test email via
swiftmailer:email:send
it still uses the default command - which of course fails with
[Swift_TransportException]
Process could not be started [The system cannot find the specified path.]
I am not sure what else I could try. I would really like to use the fake sendmail setup in my local environment, because sendmail can be configured to force send any email to a specific address (my address) for testing and always use a specific SMTP.
This is the output of debug:config swiftmailer:
swiftmailer:
default_mailer: default
mailers:
default:
transport: sendmail
host: 127.0.0.1
username: null
password: null
port: 25
encryption: null
command: 'C:\Program Files (x86)\sendmail\sendmail.exe -t'
url: null
timeout: 30
source_ip: null
local_domain: null
auth_mode: null
delivery_addresses: { }
logging: false
delivery_whitelist: { }

update an open issue found on github: https://github.com/symfony/swiftmailer-bundle/issues/244
so it was a hard way. but try this one in your's swiftmailer.yaml:
swiftmailer:
default_mailer: default
mailers:
default:
transport: sendmail
command: '%env(SENDMAIL_COMMAND)%'
timeout: 20
and add a new env-variable in your .env file:
SENDMAIL_COMMAND='C:\Program Files (x86)\sendmail\sendmail.exe -t'
this was found during debuging SwiftmailerExtension.php file on line 96 you can find and if statement witch can help to understand how it works

Related

Symfony4 - Swiftmailer : Connexion refused #111 with corrects identifiers and supposed good configuration

Symfony4 - Swiftmailer : Connexion refused #111
The exact error :
22:02:41 ERROR [app] Exception occurred while flushing email queue: Connection could not be established with host auth.smtp.1and1.fr [Connection refused #111]
Hello,
I'm deploying a website on my server (1and1 - Shared Web Hosting), but the thing is that I can't send emails. When I use php echo "this is the body" | mail -s "this is the subject" "to#address" it works fine but I can't get the proper configuration with Swiftmailer.
I searched a lot of time and most of topics talks about Symfony 1.4, 2 sometimes 3.
I have another website working fine on this same server with Symfony3, and it works.
So I've tried to copy the working config of Symfony3 on the current web site but it did'nt works because it seems that 'mail' transport is not supported anymore in Symfony4.
I have also tried mailer and sendmail which give another errors.
I've followed 1and1 configuration on my account
but i've tested others combinations to be sure :
ssl + port 25 = Connection timed out #110
ssl + port 465 = Connection timed out #110
ssl + port 993 = Connection refused #111
tls + port 25 = Connection timed out #110
tls + port 465 = Connection timed out #110
tls + port 993 = Connection refused #111
Port 993 seems to work but, but something is blocking the connexion and i can't
figuring what.
And the password / id is correct, i even changed the password to be sure.
So i don't know what i'm doing wrong, maybe it should be simple but i don't get it.
Thanks
Configuration :
config/package/swiftmailer.yaml according to Mailer Configuration Reference
swiftmailer:
default_mailer: default
mailers:
default:
url: '%env(MAILER_URL)%' #defined in .env
spool:
type: memory
transport: smtp
command: '/usr/sbin/sendmail -bs'
username: ******.*****#*****.***.***
password: ************
host: auth.smtp.1and1.fr
port: 993
timeout: 20
encryption: ssl
auth_mode: login
.env according to Symfony : Using Cloud Services to Send Emails
###> symfony/framework-bundle ###
APP_ENV=dev
###< symfony/framework-bundle ###
###> symfony/swiftmailer-bundle ###
MAILER_URL=smtp://auth.smtp.1and1.fr:993?encryption=ssl&auth_mode=login&username=******.*****%40******.****.com&password=******
###< symfony/swiftmailer-bundle ###
###> doctrine/doctrine-bundle ###
...

Akeneo 2.1.8 : Sending e-mail from console task does not follow configuration

In Akeneo 2.1.8, I'm trying to send an e-mail in a console aware container like so:
$mailer = $this->getContainer()->get('mailer');
$message = $mailer->createMessage();
// generate message
$mailer->send($message);
However, it does not look like that the Akeneo configuration is used in this way. For example: my SMTP server runs at localhost:1025, but when I start debugging this code, it appears that localhost:25 is used.
Am I missing something here? How can I use the mailer in a console command, while still using the Akeneo configuration?
You seem to use the default configuration 'localhost:25', like here
You can overload it via the parameters.yml file https://github.com/akeneo/pim-community-dev/blob/2.2/app/config/parameters.yml.dist
I got the answer to my own question. #Gaƫl, I already tried adding the configuration settings to my parameters.yml file:
parameters:
mailer_transport: smtp
mailer_host: localhost
mailer_port: 1025
mailer_user: ~
mailer_password: ~
But what I didn't do was add the port to the config.yml file:
swiftmailer:
port: "%mailer_port%"
The weird part is: if I look at the original source code this line is there, but in my project this line was missing for reasons unknown. Fixed the config.yml-file and now everything works as expected.

Symfony swiftmailer via smtp gmail on localhost openssl error

After upgrading to php 5.6 (mac os x sierra) I'm not able to send mails on my local test environment.
But sadly mail delivery via swiftmailer in Symfony does not work.
This is the error:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
What I discovered until now:
Since php 5.6 openssl seems a requirement: http://php.net/manual/en/migration56.openssl.php
Because after the Update I was not able to use file_get_contents at all without this error, so what i did was to specify a
openssl.cafile=
in my php ini like I found here: https://andrewyager.com/2016/10/04/php-on-macos-sierra-cant-access-ssl-data/
Now file_get_contents works again, but I'm not able to send swiftmailer mails via smtp.
This is my swiftmailer config:
swiftmailer:
transport: "smtp"
host: "smtp.gmail.com"
username: "%mailer_user%"
password: "%mailer_password%"
auth_mode: login
port: 587
encryption: tls
delivery_address: "%mailer_delivery_address%"
spool: { type: memory }
Do I have to provide my cafile on any other place to symfony/swiftmailer?
I already found this: PHP - Swiftmailer using STARTTLS and self signed certificates
But to hardcode solutions like this is not an option, because I want to deploy the codebase without changing this every time. I prefer to solve this issue on a system level.
It seems, that the problem is the self-signed certificate as you are on your local machine.
You must add the following to your config.yml (or if you prefer to separate test/dev from prod in the subsequent config_dev.yml):
swiftmailer:
# ... your other config
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
This way it should work and you have dev and prod env separated.
Look also here: https://github.com/symfony/swiftmailer-bundle/tree/master/Tests/DependencyInjection/Fixtures/config/yml
You can create your own service that would implement this behaviour.
Check this solution, also you can create own factory for Swift_SmtpTransport:
https://github.com/swiftmailer/swiftmailer/issues/544#issuecomment-220103233
It works for me in swiftmailer configuration:
swiftmailer:
...
encryption: null
...

symfony swiftmailer: mail not sent in prod-environment

I have a symfony 2.8 app, with fosuserbundle implemented. In the dev environment, the registration confirm mails are sent, but not in the prod environment. There is no log message and the smpt configuration is correct.
sf version: 2.8.1
swiftmailer-bundle version: current (compatible with sf version; 2.* in composer json)
fosuserbundle: 1.3.5 (* in composer)
dev-config:
imports:
- { resource: config.yml }
framework:
router:
resource: "%kernel.root_dir%/config/routing_dev.yml"
#strict_requirements: true
profiler: { only_exceptions: true }
web_profiler:
toolbar: true
intercept_redirects: true
assetic:
use_controller: true
Has anyone the same problem?
edit
I just tried a mail with the following console command in prod env: php sf --env=prod swiftmailer:email:send
Terminal output:
#!/usr/bin/env php
From: test#antondachauer.de
To: mail#antondachauer.de
Subject: test
Body: test
Sent 1 emails
But the mail has not been sent. In the dev env, it works also in terminal.
I tried all the solutions mentioned here,
which is "gethostbyname" and "change smtp of Gmail" but it did not work.
After a few days of digging, I found a solution, you need to change the encryption to tls, and add ssl in stream_options in config. It's not recommended according to the security standpoint, but it works in my case.
parameters.yml
mailer_prod_encryption: tls
config.yml
swiftmailer:
transport: "%mailer_dev_transport%"
host: "%mailer_dev_host%"
username: "%mailer_dev_user%"
password: "%mailer_dev_password%"
encryption: "%mailer_dev_encryption%"
auth_mode: "%mailer_dev_auth_mode%"
spool: { type: memory }
port: 25
stream_options:
ssl:
allow_self_signed: true
verify_peer: false

I can't send email on production environment

I'm working in a symfony project (version 2.3.35) and I can't send emails in the production environment. Mails are sent perfectly in others environments except in production environment.
For instance, when I send an email by command line:
this work:
php app/console swiftmailer:email:send --env=dev
But, this doesn't work:
php app/console swiftmailer:email:send --env=prod
The result is the same for both:
From: from_email#gmail.com
To: my_email#gmail.com
Subject: lorem ipsum
Body: lorem ipsum
Sent 1 emails
But with --env=prod option I don't get any email.
I've tried by setting the parameters.yml and config.yml hundred of times like in this post, but it's still not working.
app/config/config.yml
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_username%
password: %mailer_password%
spool: { type: memory }
app/config/parameters.yml
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_username: my_email#gmail.com
mailer_password: apswd
Besides:
The prod.log and dev.log don't have any errors about swiftmailer.
Any suggestion?
Thanks in advance.
EDIT:
On the server where the project is stored (Ubuntu Server 12.04), I can send emails using the command line or by using a script php (with mail() function). Both work perfectly.
THE SOLUTION
I finally solved the problem by using:
php app/console cache:clear --env=prod
I don't know why, but this command has solved the problem. After this command the emails were sent perfectly from production environment.
Thanks to everybody.
Mails are sent perfectly in others environments except in production environment.
Try logging into the production server(s) and attempt to send an email from the command line.
You may need to work with the sysadmins to see if sending email is allowed from production systems.
You may need to work with the security/networking folks to see if the email port (typically port 25) is blocked.

Categories