Send email using gmail smtp

October 11, 2019 159 views
DigitalOcean Cloud Firewalls Email

I’ve followed the tutorial here : https://cloudsupport.digitalocean.com/s/

I’ve tried using port 465 however I had an error so as I use tls I have changed the port to 587, I think 587 is for tls?

I’m getting the following error:

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. a7sm12831008wra.43 - gsmtp

I’m trying to send email from Expressionengine, I have the following email settings:

$config['email_newline'] = "\r\n";
$config['email_crlf'] = "\r\n";
$config['smtp_crypto'] = 'tls';
Inbound Rules
Custom      TCP     25              All IPv4 All IPv6   More 
HTTP        TCP     80              All IPv4 All IPv6   More 
HTTPS       TCP     443         All IPv4 All IPv6   More 
Custom      TCP     587         All IPv4 All IPv6   More 

Outbound Rules
ICMP        ICMP        All IPv4    All IPv6    More 
All TCP     TCP         All ports   All IPv4 All IPv6   More 
Custom      TCP         587     All IPv4 All IPv6   More 
All UDP     UDP         All ports   All IPv4 All IPv6   More 

Any ideas?

4 Answers

Hey, @ecell100

On port 587 you need to use STARTTLS. You can first check if you can connect on this port by using telnet:

telnet smtp.gmail.com 587

Let me know what’s the output of this command.

  • Thank you for your reply:

    Trying 2a00:1450:400c:c09::6c...
    Connected to gmail-smtp-msa.l.google.com.
    Escape character is '^]'.
    220 smtp.gmail.com ESMTP w3sm19952071wru.5 - gsmtp
    

    I have to ‘quit’ to exit this connection, if I use port 465 it exits by itself:

    Trying 2a00:1450:400c:c09::6d...
    Connected to gmail-smtp-msa.l.google.com.
    Escape character is '^]'.
    Connection closed by foreign host.
    

I changed the host to ‘ssl://smtp.gmail.com’ port 465 and it works now!

I would assume that you can connect on port 25 as well. It seems that nothing is wrong with the connection itself.

Another thing to add is to enable IMAP from your Gmail account.
Login to Gmail and click the gear icon on your top right side of the page, then click Settings –> Forwarding and POP/IMAP –> IMAP access –> Click Enable –> Save Changes

May I ask what was the exact error on port 465? Make sure this port is open for Outbound TCP as well.

  • I didn’t mention, I had the host set to just ‘smtp.gmail.com’ before.

    I don’t actually have access to the gmail account as it belongs to a client, which makes things a little awkward.

    I can ask him to enable IMAP, what does this do?

    The error I had previously on 465 was:
    'Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.’

Have another answer? Share your knowledge.