Problem on Symfony Mailer with SMTP and certificate ssl not valid - symfony

Symfony version(s) affected: 4.4.3
Mailer component (not swiftmailer)
Description
i try to send a mail on the SMTP server but this one don't have a certicate valid.
So How to disable the ssl ?
How to reproduce
the error :
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

You can disable it if you'r using swiftmailer
swiftmailer:
stream_options:
ssl:
verify_peer: false
verify_peer_name: false```

Related

Contao > 4.3 sending emails with sendmail throw error on some providers

Older Versions of Contao (till 4.3) working like expected with sending emails via sendmail.
After upgrade to Contao 4.9 I got some errors at Providers like 1u1 / ionos or mittwald.
The error in the logs sound like:
"Expected response code 220 but got an empty response"
Sending Mails from CLI of the Server (means if logged in via SSH) working like expected:sendmail test" |
/usr/sbin/sendmail -t -v -f sender#domain.com reciepient#otherOne.com
The solution is to add this to config/config.yml
swiftmailer:
default_mailer: default
mailers:
default:
url: '%env(MAILER_URL)%'
transport: sendmail
command: '/usr/sbin/sendmail -t -i'
After that, clear the Contao-Cache (e.g. via contao-manager.phar) and give it a try.
The reason for that issue is, that by default the swiftMailer use sendmail -bs as command, which means that sendmail run as standalone Service.
Depending at the way your provider configure it's sendmail, this will be the cause of the error.
If you update symfony/swiftmailer-bundle to version 3.5.0, then the default value used for the sendmail command will be read from the PHP configuration. See https://github.com/symfony/swiftmailer-bundle/pull/302
So provided the PHP configuration of your hosting environment contains the correct command in sendmail_path, sending emails should work without any changes.

Failed to authenticate on Gmail SMTP server

I'm trying to send emails via gmail in a Symfony 5 online application.
Here is my configuration (swiftmailer.yaml) :
swiftmailer:
transport: gmail
auth_mode: login
port: 465
host: smtp.gmail.com
username: my_username
password: '%env(MAILER_GMAIL_PASSWORD)%'
spool: { type: 'memory' }
And here is the error that I've got :
app.ERROR: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "my_username" using 1 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "534", with message "534-5.7.14 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 a10sm1287053wrm.87 - gsmtp ". [] []
I followed the steps on the link in the error (https://support.google.com/mail/answer/78754), and nothing has changed.
Any suggestion?
I fixed my issue deleting this line in configuration of swiftmailer:
auth_mode: login

Symfony 4 Swift Mailer doesn't send mails

I´m working in a localhost server with Symfony 4 and FOSUserBundle. I can't manage to receive the email confirmation when a new user is registered.
I have tried the following post but it´s not working in my case:
Symfony 4 SwiftMailer Gmail : Email not sent
I have tried to configure SwiftMailer to send using gmail smtp server and mailtrap smtp server without success. Also I have checked dev.log and no errors are found.
I´m not sure which is the right file to configure Swift Mailer (.env or packages/dev/swiftmailer.yaml). Right now the configuration is the following:
.env file:
MAILER_URL=gmail://***#gmail.com:***#localhost
swiftmailer.yaml:
swiftmailer:
transport: gmail
username: ***#gmail.com
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
Any ideas? It´s not mandatory to use gmail as the smtp server.
Thanks beforehand.
SOLUTION:
The problem was in the /config/test/fos_user.yaml file:
I changed:
service:
mailer: 'fos_user.mailer.noop'
To:
service:
mailer: 'fos_user.mailer.default'
Documentation: http://symfony.com/doc/master/bundles/FOSUserBundle/emails.html
Also I have accepted less secure connections from the gmail account setting in order to work.
I had the same problem with Symfony 4. My packages version
swiftmailer/swiftmailer v6.1.0
symfony/swiftmailer-bundle v3.2.2
When I used configuration:
swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
The emails were not send and no exception occurred.
Then I change the settings into:
swiftmailer:
url: '%env(MAILER_URL)%'
spool:
type: 'file'
path: '%kernel.cache_dir%/swiftmailer/spool'
And tried command:
php bin/console swiftmailer:spool:send --env=dev -vvv
And I saw the error:
[Swift_SwiftException]
No IDN encoder found (install the intl extension or the true/punycode package
So I installed true/punycode package via:
composer req true/punycode
and now emails are sending fine also with spool memory.
Default behaviour of Symfony mailer is to send the email messages immediately, but as you configured, it will "spool" the emails instead of sending them directly.
spool: { type: 'memory' }
Sending the messages from the spool is done separately, with a console command:
php bin/console swiftmailer:spool:send --env=dev
#see more docs here
UPDATE:
As #nek said on the first comment, the the memory spool send the mail immediately (if none exception occured). The spool:send command is only required when using the file spool.

PHPMailer: Error number 2. "Error notice: stream_socket_client()

I am getting the following error (using the WP Mail SMTP Plugin).
Any idea how to resolve this?
(All ports, passwords, etc are correct)
Thanks
Versions:
WordPress: 4.9.1
WordPress MS: No
PHP: 5.6.31-4+wpengine10
WP Mail SMTP: 1.2.2
Params:
Mailer: smtp
Constants: No
ErrorInfo: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Host: smtp.hosts.co.uk
Port: 465
SMTPSecure: ssl
SMTPAutoTLS: bool(false)
SMTPAuth: bool(true)
Server:
OpenSSL: Yes
SMTP Debug:
2018-01-15 15:54:32 Connection: opening to ssl://smtp.hosts.co.uk:465, timeout=300, options=array ()
2018-01-15 15:54:39 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://smtp.hosts.co.uk:465 (Connection timed out)
2018-01-15 15:54:39 SMTP ERROR: Failed to connect to server: Connection timed out (110)
2018-01-15 15:54:39 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
It looks like your ISP is blocking outbound SMTP. How to diagnose this is covered in the troubleshooting guide linked from the error message.
I can get to your host on that port, so it's definitely an issue with your network, not your code. You should ask your ISP or read their support docs about how they want you to send email.

Unable to send emails through gmail with swiftmailer in symfony2.3 application

I'm trying to send emails using gmail configuration but I can't.
I'm not having any errors; I also checked the symfony log files.
Nothing crashed, but no emails are sent :(
I also ran the swiftmailer:spool:send command (maybe the emails were in the spool) and as a result I received: sent 0 emails.
I'm using the dev environment, in my config_dev.yml:
swiftmailer:
transport: gmail
username: myuser#gmail.com
password: mypass
In the controller(just for test):
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('send#example.com')
->setTo('myemail#mydomain.com')
->setBody(
"some test body"
)
;
$this->get('mailer')->send($message);
Thanks in advance
UPDATE:
I switch to prod environment, same results: no errors... until i ran the command and I got this error:
[Swift_TransportException]
Connection could not be established with host smtp.gmail.com [Unable to fin
d the socket transport "ssl" - did you forget to enable it when you configu
red PHP? #50346848]
Then, I uncomment this line in the php.ini
extension=php_openssl.dll
but nothing, the same result :(
I also modified the memory to file in swiftmailer config and the email is there, in cache:
app\cache\prod\swiftmailer\spool
PS: I'm not behind any proxy
Did you check the profiler (you can know if some emails were sent, or at least spooled)? Did you try in the prod environment ?
I remember a similar issue with Swiftmailer on a dev env in a project I did. To test it, I changed spool: { type: memory } to spool: { type: file } and I checked the mails in the dev cache directory.

Resources