Test mail using gmail smtp using swiftmailer? [duplicate] - php

When I try to send an e-mail through my website running Laravel 4, I get this exception:
{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Here is my mail config:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'mymail#gmail.com', 'name' => 'myname'),
'encryption' => 'ssl',
'username' => 'mymail#gmail.com',
'password' => 'lol',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I've tried the disable link i've found by googling this issue except it didn't make a difference.
Is there a way to tell Google "stop blocking this IP, it's me" ?

I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.
They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.
Things will actually be more straight forward if you visit that link already logged in into your Gmail account.
Warning
As #kodfire stated:
On May 30, 2022, this setting will no longer be available.
support.google.com/accounts?p=less-secure-apps&hl=en

Go to this link and disable unlock Captcha
https://accounts.google.com/b/0/DisplayUnlockCaptcha

Try this:
Change port to 587
Goto gmail setting https://www.google.com/settings/security/lesssecureapps
and active it.

https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),

I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.
So, This is how it worked for me (100%):
Activate 2 step Verification in google
Now you will be able to create app. Open it.
Create new app (other app) and give your app name.
Now generate password.
Next in laravel, Goto .env file and change
MAIL_USERNAME= 'App Name you created'
MAIL_PASSWORD= 'Generated Password for that app'
This should be able to send emails from your gmail account.
Please leave a comment if it doesn't works for you.

Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.

Remove the #gmail.com from username, already you mentioned smtp. So no need #gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.

Related

Laravel mail sending is not working in the cloud instance [duplicate]

When I try to send an e-mail through my website running Laravel 4, I get this exception:
{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Here is my mail config:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'mymail#gmail.com', 'name' => 'myname'),
'encryption' => 'ssl',
'username' => 'mymail#gmail.com',
'password' => 'lol',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I've tried the disable link i've found by googling this issue except it didn't make a difference.
Is there a way to tell Google "stop blocking this IP, it's me" ?
I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.
They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.
Things will actually be more straight forward if you visit that link already logged in into your Gmail account.
Warning
As #kodfire stated:
On May 30, 2022, this setting will no longer be available.
support.google.com/accounts?p=less-secure-apps&hl=en
Go to this link and disable unlock Captcha
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Try this:
Change port to 587
Goto gmail setting https://www.google.com/settings/security/lesssecureapps
and active it.
https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.
So, This is how it worked for me (100%):
Activate 2 step Verification in google
Now you will be able to create app. Open it.
Create new app (other app) and give your app name.
Now generate password.
Next in laravel, Goto .env file and change
MAIL_USERNAME= 'App Name you created'
MAIL_PASSWORD= 'Generated Password for that app'
This should be able to send emails from your gmail account.
Please leave a comment if it doesn't works for you.
Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.
Remove the #gmail.com from username, already you mentioned smtp. So no need #gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.

Using gmail smtp via Laravel: [Connection timed out #110]

I know this question is asked many times and have different solutions and I have tried all but no one has worked. This is my settings.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=abc#mydomain.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
And application is currently running on Centos 7 OS.
I always get
Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [Connection timed out #110]
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'ssl', 'host' => 'smtp.gmail.com', 'port' => '465', 'timeout' => '30', 'blocking' => '1', 'tls' => false, 'type' => '1', 'stream_context_options' => array())) in AbstractSmtpTransport.php line 113
I have tried all solutions, by Replacing: smtp.gmail.com with 173.194.65.108, or replacing smtp.gmail.com by gmail-smtp-msa.l.google.com. When I do these two steps, it got server not found error.
If I change mail driver from smtp to sendmail or mail, no error is thrown but no email is sent.
If I use ip address of smtp.gmail.com, I got same result. If I change port from 465 to 587 and encryption from ssl to tls, nothing happens.
I have also created a file in etc/gai.conf and put precedence ::ffff:0:0/96 100. It worked one time. But later after two hours, it stopped working and started throwing same error.
I have also tried using my gmail id but all in vain.
The only solution that I couldn't be able to test is verifying httpd_can_sendmail as whenever I run command getsebool httpd_can_sendmail I get getsebool: SELinux is disabled. Is this the problem or is there any other way to get it fixed?
Here is my working mail config file:
return [
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => ['address' => '*******#gmail.com', 'name' => '****'],
'encryption' => 'tls',
'username' => '*******#gmail.com',
'password' => '*******',
'sendmail' => '/usr/sbin/sendmail -bs',
];
but from your question i can see you already tried all this, so i can assume it is a network problem based on error 'connection time out', what i mean is that something is blocking your connection, it might be your firewall if you have.
so first you should check that the port 587 is open, or you can check if other application can connect with smtp.gmail.com (don't know how to do it in centOs).
And at last this might not be a problem but you have to enable 'Allow less secure apps' in your google account just for testing. (This is not permanent solution but for testing, if it works then you should enable two step verification in google account and then create new application, you can create new special password which you can use as your password for smtp server)
In my case it was necessary to clear config cache to pull up .env file new settings
php artisan config:cache
Since you are using gmail, but I don't know what password you are setting, the MAIL_PASSWORD variable must be the same as the gmail application password. In this case, Gmail provides a third-party application service so that these, (in this case your application), can send emails using this type of authentication.

Cannot send email from Yii SwiftMail to GMail: Expected response code 250 but got code "535"

I got this error code:
Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/answer/14257
However, I'm using TLS so how could it possible be more secure?!
There are a few other questions, but they are not for Yii.
Some code:
Yii::$app->mailer->setTransport([
'class' => 'Swift_SmtpTransport',
'host' => BestSales::getConfigValue('smtp.host'),
'username' => BestSales::getConfigValue('smtp.username'),
'password' => BestSales::decrypt(BestSales::getConfigValue('smtp.password.encrypted')),
'port' => BestSales::getConfigValue('smtp.port'),
'encryption' => BestSales::getConfigValue('smtp.encryption'), // 'tls', 'ssl'
]);
Values:
[
'smtp.host' => 'smtp.gmail.com',
'smtp.username' => 'contact#xxxxxxxxxx.com',
'smtp.password.encrypted' => 'xxxxxxxxxxx',
'smtp.port' => '587',
'smtp.encryption' => 'tls',
]
I logged into Gmail and found this message:
Sign-in attempt prevented
Hi BestSales,
Someone just tried to sign in to your Google Account contact#xxxxxxxx.com from an app that doesn't meet modern security standards.
Details:
Tuesday, 17 May 2016 23:27 (Eastern Daylight Time)
Ashburn, VA, USA*
We strongly recommend that you use a secure app, like Gmail, to access your account. All apps made by Google meet these security standards. Using a less secure app, on the other hand, could leave your account vulnerable. Learn more.
Google stopped this sign-in attempt, but you should review your recently used devices
The Yii docs says 'tls' is an option. http://www.yiiframework.com/doc-2.0/yii-swiftmailer-mailer.html
Yes, I verified the decrypted value is the correct password. I've already visited https://accounts.google.com/DisplayUnlockCaptcha. I can't turn on 2-factor because I don't own the account and it needs a phone number. I can't turn on 'allow insecure access' right now as it's a client's account, but I've asked. (I'd rather not allow insecure access though.)
1. Enable the 2-step verification
2. Create App Passwdord to be use by your system HERE and use it
3. Now go to .env file and make these changes
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail#gmail.com
MAIL_PASSWORD=password generated from app password
MAIL_ENCRYPTION=tls
This worked fine on mine.
For 2-step verification
https://www.google.com/landing/2step/
For App Password
https://security.google.com/settings/security/apppasswords
First of all, use ssl in encryption and value 465 in port, because
of the two factor authentication do not use your gmail password,
but create a gmail APP Password which is better to give access
from there to a less secure application, here is the link for
creating app passwords.
Hey after couple hours of resarching have some tips to you:
1 - Enable less security app access on gmail
2 - Access this link : https://www.google.com/accounts/DisplayUnlockCaptcha
3 - on config/web.php add these params:
'encryption' => 'tls',
'streamOptions' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
try
'smtp.port' => '465',
'smtp.encryption' => 'ssl',
You have to log into you gmail account and go the the security settings and notify them that it was you trying to access your account. They put a block on it because it looked suspicious.
Go to this link and try again.

Laravel Gmail not working, "Username and Password not accepted. Learn more..."

When I try to send an e-mail through my website running Laravel 4, I get this exception:
{"error":{"type":"Swift_TransportException","message":"Expected response code 250 but got code \"535\", with message \"535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 http:\/\/support.google.com\/mail\/bin\/answer.py?answer=14257 y70sm14744455qgd.3 - gsmtp\r\n\"","file":"\/var\/www\/vendor\/swiftmailer\/swiftmailer\/lib\/classes\/Swift\/Transport\/AbstractSmtpTransport.php","line":386}}
Here is my mail config:
return array(
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'from' => array('address' => 'mymail#gmail.com', 'name' => 'myname'),
'encryption' => 'ssl',
'username' => 'mymail#gmail.com',
'password' => 'lol',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
I've tried the disable link i've found by googling this issue except it didn't make a difference.
Is there a way to tell Google "stop blocking this IP, it's me" ?
I tried the same thing and got the same error. So i personally checked my gmail account and i had a message from Gmail itself letting me know that they'd blocked an access attempt to my email account.
They showed an option to disable this security setting by visiting https://www.google.com/settings/security/lesssecureapps.
Things will actually be more straight forward if you visit that link already logged in into your Gmail account.
Warning
As #kodfire stated:
On May 30, 2022, this setting will no longer be available.
support.google.com/accounts?p=less-secure-apps&hl=en
Go to this link and disable unlock Captcha
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Try this:
Change port to 587
Goto gmail setting https://www.google.com/settings/security/lesssecureapps
and active it.
https://www.google.com/settings/security/lesssecureapps and active it.
https://accounts.google.com/b/0/DisplayUnlockCaptcha and active it.
'port' => env('MAIL_PORT', 587), <br>
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
I had lot of issues finding answer for this. Then after doing lot of trial and error i have found an solution to this. Most of the solution above worked for other but it help me upto 50%.
So, This is how it worked for me (100%):
Activate 2 step Verification in google
Now you will be able to create app. Open it.
Create new app (other app) and give your app name.
Now generate password.
Next in laravel, Goto .env file and change
MAIL_USERNAME= 'App Name you created'
MAIL_PASSWORD= 'Generated Password for that app'
This should be able to send emails from your gmail account.
Please leave a comment if it doesn't works for you.
Did you activate 2-step google authentification? If so, you need to define a new "application-specific password" password: http://www.google.com/landing/2step/.
Remove the #gmail.com from username, already you mentioned smtp. So no need #gmail.com on your username. I'm 100% sure it is your problem, because I had that problem.

Bluehost's mail server seems not be sending my emails from Swiftmailer

I've a laravel app nad I've been testing it with gmail smtp server and It was working in my system's localhost but then I deployed it on server (blue host) and change the configuration and still the app thinks that is sending emails and it's not giving me errors but no email is delivered to corresponding email addresses....
Here's my mail.php in app folder:
return array(
'driver' => 'smtp',
'host' => 'mail.mash-up.fi',
'port' => 26,
'from' => array('address' => 'registration#mash-up.fi', 'name' => 'Admin'),
'encryption' => 'tls',
'username' => '************',
'password' => '******',
'sendmail' => '/usr/bin/sendmail -bs',
'pretend' => false,
);
where I'm doing wrong?
any help is appreciated
If you are using the BH DNS(ns1.bluehost...), then check to see that the $from address is an existing email in your BH account.
(go to your CP /domain manager and use whois info to find that out.)
or.....
maybe, you migrated the source code, but did you transfer your domain name to BH, or is it pointing to BH servers (DNS)
In that case your site is not using the BH mail servers.
example :your site content could be on BH, but if it is registered somewhere else and the DNS is not ns1.bluehost.com..etc, then your domain might be using url forwarding or framing (to bring visitors to the BH location). but your mail functions may be handled by the registrar's
hope this is not too confusing
it is also helpfull if you post your domain name here and others can help figure out as well.
Please try to check the spam folder of where your sending to. If there is nothing, make sure your "from" is truly your bluehost email account your using to send the email. If the actual sender doesn't match the "from" of the e-mail many mail clients will ignore it entirely (like hotmail), but gmail will put it in the spam folder with a warning.
The host should be your bluehost box I think. In fact on cpanel, go to email, where you create accounts. Then click on "More", select "Configure Email Client", scroll down. You will see the host name, and port.
TTL/SSL would likely need port 465, I am guessing (I use the latter, not the former like you).
Open up the laravel.logs file inside of storage > logs. It should help give you some idea of what the problem might be.

Categories