Symfony swiftmailer via smtp gmail on localhost openssl error - php

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
...

Related

Cannot get sendmail to work with Swiftmailer Bundle on Windows

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

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 SwiftmailerBundle: Gmail sends "530 5.7.0 Must issue a STARTTLS command first"

Over my SYmfony project I have configured the Swiftmailer to use the following email settings:
On config.yml:
swiftmailer:
transport: 'smtp'
host: 'smtp.gmail.com'
port: '587'
encryption: 'tls'
username: 'gmailUser'
password: 'gmailPasswd'
auth_mode: 'login'
But when I try to send an email over my via Swiftmailer I get the response:
Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. i61sm9367124edc.32 - gsmtp
I also tried the following settings:
swiftmailer:
transport: 'smtp'
host: 'smtp.gmail.com'
port: '465'
encryption: 'ssl'
username: 'gmailUser'
password: 'gmailPasswd'
auth_mode: 'login'
And I try to figure out why without any idea. Do you know why?
Edit 1:
I try to figure out if openssl is installed into php anf I run:
php -m | grep ssl
And I get response:
openssl
Edit 2:
Also php has openssl support:
In the end I had to use the following config:
swiftmailer:
transport: 'gmail'
username: '%mailer_user%'
password: '%mailer_password%'
I guess that Swiftmailer has specific configuration for gmail.
(Or because it is pain in the neck to setup with gmail, so swiftmailer developers provided a nice pain-free alias)

PHP Swiftmailer with Zoho smtp server not sending mail

I'm using Swiftmailer on a Symfony2. I'm also using Zoho mail to host my mail server and I have configured Swiftmailer using the smpt details provided by Zoho, but it looks like something is wrong because the following exception is thrown:
PHP Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host 127.0.0.1 [Connection refused #111]'
My parameters.yml file looks like:
parameters:
mailer_transport: smtp
mailer_host: smtp.zoho.com
mailer_port: 465
mailer_encryption: ssl
mailer_user: my_username
mailer_password: my_password
mailer_authmode: plain
and my config.yml:
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
port: "%mailer_port%"
encryption: "%mailer_encryption%"
username: "%mailer_user%"
password: "%mailer_password%"
auth_mode: "%mailer_authmode%"
spool: { type: memory }
I have tested the connection using telnet and everything seems to be alright:
root:/# telnet smtp.zoho.com 465
Trying 74.201.154.90...
Connected to smtp.zoho.com.
Escape character is '^]'.
What am I missing?
Thanks!
Well, if you parameters.yml is well loaded then i think i know the problem where it comes from, i think your webhost doesn't allow ssl connection port 465, it refuses the connection thats what the error 111 means, try first to connect using TLS security with port 587. If you still want to use 465 try contacting your web hosting to check that port.
Edit :
Remove the "" should fix it
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
port: %mailer_port%
encryption: %mailer_encryption%
username: %mailer_user%
password: %mailer_password%
auth_mode: %mailer_authmode%
spool: { type: memory }
Change mailer_authmode: plain to mailer_authmode: login.
After trying with all the solutions (in my development and the production machine) I've tryied PhpMailer. It works perfectly.
I think the problem is in SwiftMailer's code.
You need to log into zoho and set up an application specific password. You can find it under Security -> Two Factor Authentication. Use that password instead of your account password.
Please note that Zoho Mail does not offer IMAP/POP support anymore with their free plan:
```
FREE PLAN
Up to 25 Users
5GB* /User, 25MB Attachment Limit
Webmail access only+. Single domain hosting.
```
+IMAP/POP Support Available exclusively with the paid plans.
https://www.zoho.com/workplace/pricing.html?src=zmail
Old free plans (registered before 2018???) seem to still have IMAP/POP Support Available
Source: https://help.zoho.com/portal/community/topic/zoho-free-tier-pop-imap-activesync-no-longer-free

Categories