PHP: Use Google's SMTP relay with SwiftMailer - php

I want to use Google's SMTP relay service as a SMTP server in PHP.
The IP address is whitelisted for the SMTP relay service, and I am using the SwiftMailer as a PHP library to send emails.
I configured the SMTP service to use TLS encryption, and set the following parameters for the SwiftMailer:
transport: smtp
host: smtp-relay.gmail.com
port: 587
encryption: tls
auth_mode: login
I was able to send emails via telnet, but when I try to send emails with SwiftMailer with the above configuration, I receive the following error:
[CLOSED] IMAP connection broken (server response) (errflg=2)
How can I configure the SwiftMailer to use Google SMTP relay service as its SMTP server? Is it ever possible?

had similar issue, when I provided the sender_address (that I'm checking on google relay server), it worked.
(I'm not using auth mode though, just IP source defined in google gsuite)
swiftmailer:
transport: smtp
host: smtp-relay.gmail.com
port: 587
encryption: tls
sender_address: support#example.com

Since this seems to be not that well documented here is what worked for me after reading through different sources. Gmail itself wrote that it's important to send the HELO- or EHLO command, which can be done by setting the local domain (supported since swiftmailer-bundle 2.4.0). Otherwise you might run into DoS issues. See the official Google documentation for more details.
transport: smtp
host: smtp-relay.gmail.com
port: 587
encryption: tls
auth_mode: login
username: contact#yourdomain.com
password: 'yourpassword'
local_domain: yourdomain.com
Additionally I did add the IPv4 and the IPv6 address of my server within the Google Admin Console within the SMTP-Relay settings and activated TLS + SMTP-authentication, since I definitely want to have an encrypted connection between my server and gmail.

Related

How to configure WP Mail SMTP plugin for localhost

I am struggle for 2 days with this problem.
I am going to send email from my localhost using WordPress.
I am using wp_mail() function so I decided to use WP Mail SMTP plugin.
But I have a problem while configuring it.
This is screen shot of my configuration.
When I try to send test email, it fails.
Anyone please help me
From the plugins list, I've noticed you are using Postman SMTP plugin, which causes conflict with the WP Mail SMTP plugin. If you disable that plugin, it will work correctly.
Try with following SMTP setting for gmail to configure on localhost with your plugin :
HOST : smtp.gmail.com
PORT : 587
USERNAME : Your_gmail_ID
PASSWORD : Your_gamil_Password
Encryption : TLS
NOTE : Make sure your gmail account must be Allow less secure apps: ON. You can turn on less secure apps for your account using THIS URL
UPDATE
As discussed please use following setting in your plugin :
WP Mail SMTP Settings
From Email : Your_gmail_EmailID
From Name : Your_name
Mailer : Send all WordPress emails via SMTP.
Return Path : checked
After that Click on Save Changes
Now under SMTP Options
SMTP Host : smtp.gmail.com
SMTP Port : 587
Encryption : Use TLS encryption.
Authentication : Yes: Use SMTP authentication.
Username : Your_gmail_EmailID
Password : Your_gamil_EmailPassword
After that Click on Save Changes
install plugin wp mail smtp
then in general settings
From Email:your email
mailer: other smtp
SMTP Host:smtp.gmail.com
Encryption:ssl
port:456
SMTP Username: your gmail address
SMTP Password: your gmail password
save settings
after that test email by sending one to
Send To: email that you want to receive email on
and make sure your SMTP Username(your gmail) account has turn on less secure apps
hope i helped.

Send emails from localhost?

im kinda stuck, i have read some threads where they use google smtp to send mails from localhost.
Im using xampp right now and im trying to use google smtp but it doesn't work what have i done wrong ?
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\page.php on line 48
My Code in php.ini:
sendmail_from = T***#gmail.com
Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: T***#gmail.com
Gmail SMTP password: ****
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes
You have to set the SMTP-Server, Port and authentication credentials in your php.ini.
But for this it's much easier to use the wonderful PHPMailer class.
It's very easy to implement and to use.
You can easily send complex emails (HTML, Attachments) and it has a good support for external SMTP server, including e.g. encryption.
Just take a look at the examples in the "examples" folder or scroll down at the linked page where is an example using SMTP auth in the first code-block.

Amazon SES STARTTLS SMTP & ExpressionEngine

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;

Gmail SMTP issue

I have a problem sending an email using gmail's smtp server
Let me explain my situation. 1 week ago, i could send emails using php using smtp. Yesterday my host shifted their websites including mine to a different server. After that i am not able to send emails.
I tested the email scripts on my local machine and it worked just fine.
I am currently using phpmailer to send emails. When the error occurred, i enabled debugging on the php script. I ran the debugging enable version on the remote web server and my local machine.
Here is the output:
Local machine (works)
SMTP -> FROM SERVER:220 mx.google.com ESMTP dj6sm9229359qab.3
SMTP -> FROM SERVER: 250-mx.google.com at your service, [155.41.29.55] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250 ENHANCEDSTATUSCODES
SMTP -> FROM SERVER:250 2.1.0 OK dj6sm9229359qab.3
SMTP -> FROM SERVER:250 2.1.5 OK dj6sm9229359qab.3
SMTP -> FROM SERVER:354 Go ahead dj6sm9229359qab.3
SMTP -> FROM SERVER:250 2.0.0 OK 1350437987 dj6sm9229359qab.3
Message sent!
remote server (doesnt work)
SMTP -> FROM SERVER:220-gds-wh1.get-sourced.net ESMTP Exim 4.80 #2 Tue, 16 Oct 2012 21:00:32 -0500 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-gds-wh1.get-sourced.net Hello gds-wh1.get-sourced.net [63.141.244.218] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> FROM SERVER:250 Reset OK
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
If you look closly. In my local machine it seems to have the google's mx-server address in the debug info, but in the remote machine it has the hosting providers info. I don't know if this is normal or not. I am totaly clueless
Could you help me or give me a clue as to what is wrong?
thanks,
Vidhu
Your hosting provider seems to be capturing outbound SMTP requests and forwarding them to their own SMTP server.
Are you connecting to Google on port 25? Instead, connect on port 587, the SMTP submission port. If you're already using 587, and your hosting provider is capturing THIS traffic, then send them a very nasty email threatening to switch hosting providers if they don't stop interfering with your web application immediately. This sort of BS may be tolerated by residential dial-up and DSL subscribers, but it's wholly inappropriate for web hosting and co-location.
If your provider is on the ball, they'll apologize and point you to the section in their terms and conditions that states that outbound SMTP traffic will now be automatically redirected until a removal request is placed via a support ticket.
Oh, and by the way, your new hosting provider has now captured the authentication credentials with which you authenticate with Google. Time to change passwords and implement TLS, though as far as I'm aware, TLS isn't supported by phpMailer.
Perhaps it's time to look at Swiftmailer or a commercial provider like Postmark ?
from what i see, i think you must check did you already put the correct SMTP of google (usually: smtp.gmail.com)?
and to using google smtp, it's required an authentication like user and password from your google account.

SMTP error with PHPMailer

I am getting "SMTP Error: Could not connect to SMTP host." error while trying to send mails using GMAIL SMTP and PHPMailer..
The code is working perfectly in local environment but getting error in live (bluehost) server.. Please help
Bluehost wont allow gmail SMTP connections.
Quoting article:
According to bluehost, you cannot send emails through SMTP connections from web applications hosted on bluehost. They only allow sending through their own SMTP servers.
The work around is that I setup a email account in Bluehost the same as the email I use in Google Apps. I then modified the code in Magento to send out using bluehost’s SMTP servers:
For example:
Outgoing Mail Server: (SSL) boxnumber.bluehost.com (server requires authentication)
Supported Incoming Mail Protocols:
* POP3: port 110
* POP3S (SSL/TLS): port 995
* IMAP: port 143
* IMAPS (SSL/TLS): port 993
Supported Outgoing Mail Protocols:
* SMTP: port 26
* SMTPS (SSL/TLS): port 465
And it works, it sends the email out to the customers with the right email address sent from bluehost’s local SMTP servers, so when customers reply to the email address it will arrive in my google apps mail box.

Categories