I am trying to send mail using Amazon SES SMTP with STARTTLS in ExpressionEngine . I am encountering the error below.
I'm unsure why it is complaining it can't send the AUTH LOGIN command before the STARTTLS command - STARTTLS has clearly already been sent. I have tried everything I can think of, and would appreciate it if someone could point me in the right direction.
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-376766033
hello: 250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
Failed to send AUTH LOGIN command. Error: 530 Must issue a STARTTLS command first
from: 530 Authentication required
The following SMTP error was encountered: 530 Authentication required
to: 503 Error: need MAIL command
The following SMTP error was encountered: 503 Error: need MAIL command
data: 503 Error: need MAIL command
The following SMTP error was encountered: 503 Error: need MAIL command
500 Error: command not implemented
The following SMTP error was encountered: 500 Error: command not implemented
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Here's a proper fix.
It is two steps (you can safely ignore the explanations if you want) and does not involve editing any non-config Expression Engine files, so you don't break your upgrade path.
It has been tested it on two Expression Engine installs (each v2.5.3 - Build Date: 20120911) and it's working perfectly.
STEP 1 of 2: Manually edit your {INSTALLDIR}/expressionengine/config/config.php file and add the following three lines at the end:
/* These email configuration variables are required for Amazon SES */
$config['email_smtp_crypto'] = 'tls'; // TLS protocol
$config['email_newline'] = "\r\n"; // SES hangs with just \n
Explanation: The first line sets the default email cryptography to TLS (which SES requires). The second line changes the email newline character from the Expression Engine default of "\n" to the RFC 822 compliant "\r\n" (which SES also requires).
STEP 2 of 2: Via your EE Admin go to "Admin -> Email Configuration" and set the following:
Email Protocol: SMTP
SMTP Server Address: tls://YOUR-SES-SMTP-SERVER:YOUR-SES-SMTP-PORT (the incredibly important part being the tls:// in front of the address)
SMTP Username: your SES SMTP username
SMTP Password: your SES SMTP password
Explanation: Once you have an SES Verified Sender Email Address and You have been granted production access to Amazon SES (both of which need to be done through Amazon's SES Management Console), you can create an AWS account with SMTP credentials via the SES Management Console. In doing this, Amazon SES will give you your own credentials.
For example it should look like this (with wacky usernames and passwords):
EXAMPLE SMTP Server Address: tls://email-smtp.us-east-1.amazonaws.com:465
EXAMPLE SMTP Username: QSKHFTQMSQAKIAIJ6GFY
EXAMPLE SMTP Password: PeNqC2be3IAbNyhHddTbujwekIKoQE2dAhwr3FVzObjH
To test this via your EE Admin go to "Tools -> Communicate" and send an email.
Here's my fix. I haven't had time to figure our why it works but do share if you have the time.
In your EE config file add the following settings (two tls settings as there are multiple examples of either working???):
/* SMTP mail settings
-------------------------------------------------------------------*/
$config['mail_protocol'] = "smtp";
$config['email_smtp_crypto'] = "tls";
$config['smtp_crypto'] = "tls";
$config['smtp_server'] = "AWS-SMTP-ADDRESS";
$config['smtp_username'] = "AWS-SMTP-USERNAME";
$config['smtp_password'] = "AWS-SMTP-PASSWORD";
$config['smtp_port'] = "465";
$config['smtp_timeout'] = 30;
$config['email_crlf'] = "\r\n";
$config['email_newline'] = "\r\n";
Then modify the Codeigniter Email.php class along the lines of this post: http://ellislab.com/forums/viewthread/158882/
The only variation I made was to set $starttls = TRUE by default.
var $starttls = TRUE;
Related
The Requirement is that when the form is submitted the mail has to be sent the specified email address. For this I am using PHPMailer.
When I ran the code first time from localhost, I received Critical Security Alert received in Gmail, which I resolved by turning on "Allow Less Secure Apps" and also
checked and approved the security event.Now the code works perfectly in localhost powered by xampp but not in shared hosting. When I hit the submit button in the Form page present in shared hosting, I get the following message:
2020-02-25 09:48:40 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP t131sm5033428oih.35 - gsmtp<br>
2020-02-25 09:48:40 CLIENT -> SERVER: EHLO www.domain_name.com<br>
2020-02-25 09:48:40 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [AAA.BB.CCC.DD]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2020-02-25 09:48:40 CLIENT -> SERVER: STARTTLS<br>
2020-02-25 09:48:40 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS<br>
2020-02-25 09:48:44 CLIENT -> SERVER: EHLO www.domain_name.com<br>
2020-02-25 09:48:44 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [AAA.BB.CCC.DD]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
2020-02-25 09:48:44 CLIENT -> SERVER: AUTH LOGIN<br>
2020-02-25 09:48:44 SERVER -> CLIENT: 334 VXNlcm5hbWU6<br>
2020-02-25 09:48:44 CLIENT -> SERVER: [credentials hidden]<br>
2020-02-25 09:48:44 SERVER -> CLIENT: 334 UGFzc3dvcmQ6<br>
2020-02-25 09:48:44 CLIENT -> SERVER: [credentials hidden]<br>
2020-02-25 09:48:45 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 ymrjiXdYur3ddtR_6o2GrGNO2DfOQ7VhdphcGz7dq3__0gTNj1-oIXqZ__3KYGCWXt-ZC534-5.7.14 znNW-khosAGrPwCN1mDscVVYa5ms25Ann9jrAUU39WELRqwVrSmhOMGa91Ec4JRu>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 t131sm5033428oih.35 - gsmtp<br>
2020-02-25 09:48:45 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 ymrjiXdYur3ddtR_6o2GrGNO2DfOQ7VhdphcGz7dq3__0gTNj1-oIXqZ__3KYGCWXt-ZC534-5.7.14 znNW-khosAGrPwCN1mDscVVYa5ms25Ann9jrAUU39WELRqwVrSmhOMGa91Ec4JRu>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 t131sm5033428oih.35 - gsmtp<br>
SMTP Error: Could not authenticate.<br>
2020-02-25 09:48:45 CLIENT -> SERVER: QUIT<br>
2020-02-25 09:48:45 SERVER -> CLIENT: 221 2.0.0 closing connection t131sm5033428oih.35 - gsmtp<br>
SMTP Error: Could not authenticate.<br>
The PHPMailer code for sending mail follows:
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->isHTML();
$mail->Username = 'username#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('username#gmail.com');
$mail->addAddress('username#yahoo.com'); // Add a recipient
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Mail subject';
$mail->Body = 'Mail Body';
$mail->send();
echo 'done';
} catch (Exception $e) {
echo "Mailer";
}
The following actions have been taken:
Username and Password combination is correct and is not expired.
Verified manually by logging via web and also sending mails from the
localhost.
$mail->SMTPAuth=false cannot be set because majority
of shared hosting providers seems to have disabled this for security
reasons (mainly to avoid spamming and sending of unsolicited emails)
Just for others info! To resolve this issue you have to go to:
https://myaccount.google.com/security?pli=1#connectedapps
then click Allow less secure app to YES
what does it mean to be less secure app? could we change our FAQ instructions and/or implementation so that users do not need to do this extra step?
if not possible, we should at least document in FAQ that user also need to change the setting on their google security account
Your solution :
Your server not supporting phpmailer.
Your account taken as a spam read here : Prevent mail to Gmail users from being blocked or sent to spam
Use or fix App password
If you've turned on 2-Step Verification and are trying to sign in to your Google Account through a device, mobile app, or desktop app, you'll need to enter an App Password.
See more and follow steps here : Use or fix App password
If you're using SMTP (i.e. you're calling isSMTP()), you can get a detailed transcript of the SMTP conversation using the SMTPDebug property. The settings are as follows:
Enabling debug output and troubleshooting
If you are having problems connecting or sending emails through your SMTP server, the SMTP class can provide more information about the processing/errors taking place.
Use the debug functionality of the class to see what's going on in your connections. To do that, set the debug level in your script.
Allow error levels For example:
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 4; //from 1 to 4 to get more details.
I had error almost same and this code was solved my problem because of my self signed certificate.
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
Once again see SMTP Debugging
Debug levels
Debug output format
Looks like you are trying to connect by curl api or something SERVER: EHLO if so! please add your codes to question.
Well, after a long battle I somehow managed to solve this. I activated DisplayUnlockCaptcha from the following URL:
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Probably because Gmail might have viewed the logins received from PHP file lying in hosting server as untrusted requests. This is because the hosting servers may reside in different places or countries and the login authentication request received would appear different other than the one from where the Gmail account is logged in frequently. So as a security measure, it would have use some captcha mechanism in the background (which which cannot be viewed)
This was working on my live server before then suddenly it's no longer sending emails. Here's the error I got:
220 smtp30.relay.iad3a.emailsrvr.com ESMTP - VA Code Section 18.2-152.3:1 forbids use of this system for unsolicited bulk electronic mail (Spam)
hello: 250-smtp30.relay.iad3a.emailsrvr.com
250 ENHANCEDSTATUSCODES
Failed to send AUTH LOGIN command. Error: 554 5.7.1 authentication restricted (Z1E/233FC14)
from: 554 5.7.1 authentication restricted (Z1E/233FC14)
The following SMTP error was encountered: 554 5.7.1 authentication restricted (Z1E/233FC14)
to: 503 5.5.1 Bad sequence of commands
The following SMTP error was encountered: 503 5.5.1 Bad sequence of commands
data: 503 5.5.1 Bad sequence of commands
The following SMTP error was encountered: 503 5.5.1 Bad sequence of commands
221 2.7.0 Error: I can break rules, too. Goodbye.
The following SMTP error was encountered: 221 2.7.0 Error: I can break rules, too. Goodbye.
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
If I run it on my local server it's sending emails. I even tried changing the ports to 587 and I still got error and it's not sending. What would be the issue in my code. Thank you!
Here's my code:
$from = "no-reply#sample.com";
$from_name = "Daily logs";
$config['smtp_host'] = 'ssl://secure.sample.com';
$config['smtp_user'] = 'no-reply#sample.com';
$config['smtp_pass'] = ********;
$config['smtp_port'] = '465';
$config['protocol'] = 'smtp';
$config['mailtype'] = 'html';
$config['validate'] = 'FALSE';
$message = $email_message['html'];
$CI->email->initialize($config);
$CI->email->from($from, $from_name);
$CI->email->to($email_message['to']);
$CI->email->subject("Sample - ".$email_message['subject']);
$path=$_SERVER["DOCUMENT_ROOT"];
$file = $path.'/tmp/sample_data/sample_data_'.strtotime(date("y-m-d", strtotime('-1 day'))).'.csv';
$CI->email->attach($file);
$CI->email->message($message);
if(#$CI->email->send()){
$return = (object) array('http_response_code' => 200);
}
else{
echo $CI->email->print_debugger();
}
check if your configuration is write
$config['smtp_host'] = 'ssl://secure.sample.com';
$config['smtp_user'] = 'no-reply#sample.com';
$config['smtp_pass'] = ********;
I think you can try those points by gmail and then move to your own configuration just for testing your code is fine. some times the server might not allow you so don't wast time. links for gmail smtp Send email using the GMail SMTP server from a PHP page and Sending email with gmail smtp with codeigniter email library
I am trying to use PHPMailer,
I have enabled opensll and it loads
I use XAMPP and PHPStorm
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP z88sm9679wrb.26 - gsmtp
CLIENT -> SERVER: EHLO PhpStorm 2016.1.2
SERVER -> CLIENT: 501-5.5.4 HELO/EHLO argument "PhpStorm 2016.1.2" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo z88sm9679wrb.26 - gsmtp
SMTP ERROR: EHLO command failed: 501-5.5.4 HELO/EHLO argument "PhpStorm 2016.1.2" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo z88sm9679wrb.26 - gsmtp
CLIENT -> SERVER: HELO PhpStorm 2016.1.2
SERVER -> CLIENT:
SMTP ERROR: HELO command failed:
SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Here is my code
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587; //ssl : 465 --- tls:587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "te.professionnel#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "*****";
//Set who the message is to be sent from
$mail->setFrom('te.professionnel#gmail.com', 'Abou May');
//Set an alternative reply-to address
//$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('abou.may#gmail.com', 'Abou May');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I have read lots of documentation, bu I cannot figure out the reason of this error.
Can someone givz me an example code?
What is wrong ?
I read all the section on troubleshooting
"SMTP Error: Could not connect to SMTP host."
This may also appear as SMTP connect() failed or Called Mail() without being connected in debug output. This is often reported as a PHPMailer problem, but it's almost always down to local DNS failure, firewall blocking (for example as GoDaddy does) or other issue on your local network. It means that PHPMailer is unable to contact the SMTP server you have specified in the Host property, but doesn't say exactly why. It can also be caused by not having the openssl extension loaded (See encryption notes below).
I also encounter this problem before.This is not the problem of PhpMailer.But in fact,this is cause by Gmail smtp is denied the connection,therefore you cant connect.
In order for you to solve this problem,you need to
Configure an OAuth2 app in Google Developer Console.
Step is here
If you still cant manage to solve it,I recommend you to use Postmark as your mail server,it is a lot easier to set up the connection.
Here is the guide for the setup of Postmark.For me is a lot easier.Hope it helps.
This is nothing to do with gmail or oauth.
The problem is this line:
CLIENT -> SERVER: EHLO PhpStorm 2016.1.2
When PHPMailer's SMTP client says hello to a server like this, by default it passes the name returned by the internal method serverHostname(). Normally this returns something like localhost.localdomain, or mymac.local (i.e. a real host name), but if that's not available, it tries to figure out what to use - and one of the things it falls back to is the $_SERVER['SERVER_NAME'] super global, which in this case contains PhpStorm 2016.1.2 (I'd guess because you're testing using PHPStorm's built-in web server?), which is not a valid host name, hence the error. This isn't a good move on PHPStorm's part and is probably worth reporting as a bug.
Fortunately you can override automatic determination of the client hostname using the Helo property, which exists precisely for occasions like this. Just do this:
$mail->Helo = 'my.host.name';
substituting either whatever your real host name is, or by calling some other function which gives a usable result.
This image above shows the error: SMTP ERROR: Failed to connect to server: (0)
But my GMail SMTP settings are correct and working. How is this possible?
Gmail SMTP (smtp.gmail.com) use the port 587 and need a secured connection.
Otherwise it seems Google SMTP has restricted its use to Google G Suite subscriber.
You have these information and a test tool at https://www.smtper.net
I have tested myself with my G Suite mail, the test tool works great.
We presta shop 1.5 installed the smtp settings are working with php mailer but not working with prestashop smtp settings.
This is the error i am getting when sending any test email.
"Error: please check your configuration
The SMTP connection failed to start [ssl://smtp.gmail.com:465]: fsockopen returned Error Number 110 and Error String 'Connection timed out'"
I tried using ssl, tls and plain settings but didn't work with them.
Make sure you are configuring correctly smtp has some strict rules you must follow.
Mail domain name: pop.yourmail.com
SMTP server: smtp.yourmail.com
SMTP user: johndoe#yourmail.com
SMTP password: your password you use to access your mail
check those again...
hope it helps