Connection could not be established with host smtp.sendgrid.net :stream_socket_client(): unable to connect to tcp://smtp.sendgrid.net:587 - laravel

Some eamils sent successfully at start. But After that I face same issue again and again.
That's my .env variables.
Mail User Name: "apikey"
Mail Password: "Secrect API key"
Mail Host: "smtp.sendgrid.net"
Mail Encryption: "tls"
Mail Port: "587"
Mail Mailer: "smtp"
Mail From Name: "Demo"
Mail Mailer: "Demo#demo.com"
I have been apply this solution but not working.
MAIL_MAILER=sendmail
MAIL_PORT=587
MAIL_ENCRYPTION=ssl

Related

Send mail with gmail in laravel 7

I'm trying to send mail with Gmail in laravel 7. I get the result in localhost but when I upload the project on the host I recieve this error and email not send:
local.ERROR: Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) {"userId":1,"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.gmail.com :stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) at /home/wbrubkcom/libs/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269)
My env config for email is:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail
MAIL_PASSWORD=myemailpassword
MAIL_ENCRYPTION=tls
I searched in StackOverflow and test different ways such as useing Gmail app password or change port to 465 or change encryption to ssl but I don't get the result.
You need to go to
Manage google account->security->less secure app
and then allow it ..
may be that will resolve your issue.

Connection could not be established with host smtp.sendgrid.net :stream_socket_client(): unable to connect to tcp://smtp.sendgrid.net:465

I am trying to send mail using sendgrid in Laravel but it is working on localserver but as i hosted it on server it is giving me following error message:
my mail settings in .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=myusername
MAIL_PASSWORD=XXX
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info#xyz.com
MAIL_FROM_NAME=xyz
For laravel >= 7
And you are getting this error :
Connection could not be established with host smtp.sendgrid.net :stream_socket_client(): unable to connect to tcp://smtp.sendgrid.net:587 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Simply update your .env file
From:
MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=your_sendgrid_api_key
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Your Sender Name"
MAIL_FROM_ADDRESS=info#example.com
To:
MAIL_MAILER=sendMail
MAIL_DRIVER=sendMail
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=your_sendgrid_api_key
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Your Sender Name"
MAIL_FROM_ADDRESS=info#example.com
Then run this command to make sure .env changes is sync with the code.
php artisan config:cache
Update your env file to:
MAIL_MAILER=sendmail
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=apiPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info#example.com
MAIL_FROM_NAME="${APP_NAME}"
Also in your Laravel project under the config folder look for
mail.php
and make changes as follows:
'default' => env('MAIL_MAILER', 'sendmail'),
N/B: SMTP works on localhost and sendmail works on live server.
If you say it works locally but not on production server, try a php artisan config:cache on your web host server. Make sure the ENV configuration is loaded properly (if your host does not support SSH connections, you need to manually update the configuration from ENV into /app/config/* files.
If the issue persists, there are only two possibilities:
Make sure your web host allows outgoing SMTP connections.
Make sure sendgrid.net did not ban your web host outgoing SMTP IP address.
I Experienced this while using a Linode server. Apparently, Some service provider like Linode blocks an SMTP port until you reach out to them via support and ask them for unblock before you can use that PORT and send Email. That was the fix for me
when I migrated to laravel 9, sending with sendgrid didn't work anymore.
The problem was because the new symfony mailer was trying to send with ssl beside tls was set in the config file.
So in the config file, I changed the port from 587 to 465 and it worked again.

Error: connection could not be established with host smtp.gmail.com #0 - LARAVEL

I am trying send emails but I am getting the error below:
"connection could not be established with host smtp.gmail.com #0".
I made test with different ports (465, 578), with SSL and TLS and the last with the mail account and it is working.
I think that the problem is on XAMPP.
What am I doing wrong and how can I resolve it?
Try using:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=tls
MAIL_USERNAME=y*****4#gmail.com
MAIL_PASSWORD=a*****
Hope, it works for you.

Email Sending not working in CentOS 7 but same credentials works on localhost

I created an email account on godaddy which works perfectly on server and on localhost. When I did the testing on Linode server using the same email credentials. It did not work and gave 500 Internal Server Error.
Swift_TransportException Connection could not be established with host
sg6plcpnl0067.prod.sin3.secureserver.net [ #0]
Am I missing something?
.env details
MAIL_DRIVER=smtp
MAIL_HOST=sg6plcpnl0067.prod.sin3.secureserver.net
MAIL_PORT=465
MAIL_USERNAME=noreply#myserver.in
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME=myserver
MAIL_FROM_ADDRESS=noreply#myserver.in

Sending email with Joomla and Google Apps

I have the next settings in the Joomla Global Configuration panel.
**Mail Settings**
Mailer: SMTP Server
Mail from: email#mydomain.com
From Name: John Smith
Sendmail Path:
SMTP Authentication: Yes
SMTP Security: SSL
SMTP Port: 465
SMTP Username: email#mydomain.com
SMTP Password: ******
SMTP Host: gmail-smtp-in.l.google.com
I am running Joomla 1.5.14.
I have in my google apps domain both IMAP and POP enabled.
When I try to send an email with an article link by clicking the small envelope icon I get the next feedback. "The e-mail cold not be send correctly". The SMTP validation seems to work because I do not get any SMTP error but the email is not sent. Any idea would be really appreciated!
I have tested with SMTP Host as smtp.gmail.com without success.
I have tried with sendmail defined as /usr/sbin/postfix but without success.
Solution
Set sendmail path to the sendmail command or point sendmail to postfix if you have postfix installed.
Set SMTP Host to smtp.gmail.com. I would look like:
**Mail Settings**
Mailer: SMTP Server
Mail from: email#mydomain.com
From Name: John Smith
Sendmail Path: /usr/sbin/sendmail
SMTP Authentication: Yes
SMTP Security: SSL
SMTP Port: 465
SMTP Username: email#mydomain.com
SMTP Password: ******
SMTP Host: smtp.gmail.com
Mail Settings
Mailer: SMTP Server Mail from: emailmydomain.com
From Name: John Smith
Sendmail Path: /usr/sbin/sendmail
SMTP Authentication: Yes
SMTP Security: None
SMTP Port: 25
SMTP Username: emailmydomain.com
SMTP Password: **
SMTP Host: ssl://smtp.gmail.com:465
I have Virtuemart 1.1.4 with Joomla! 1.5.15.
The configuration that works for me was (both for virtuemart and joomla contacts):
Mail Settings
Mailer: SMTP Server
Mail from: email#mydomain.com
From Name: John Smith
Sendmail Path: /usr/sbin/sendmail
SMTP Authentication: Yes
SMTP Security: None
SMTP Port: 25
SMTP Username: email#mydomain.com
SMTP Password: ******
SMTP Host: ssl://smtp.gmail.com:465

Resources