ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is smtp configuration for gmail possible?

October 07, 2010 5:45am

Subscribe [3]
  • #1 / Oct 07, 2010 5:45am

    humanhand

    2 posts

    I did some searching and haven’t seen any relatively recent postings on this.  Is it possible to configure the smtp settings to work with smtp.gmail.com?

    After tracing through the EE_Email.php file I learned that EE uses codeigniter’s Email.php library file so I searched their forums too and found this thread.

    Right now I’ve just played with the smtp settings and not messed with any *Email.php files.

    I should note that I was able to get EE to send email through sendmail and php mail but would really prefer to use gmail through smtp if possible. 
    If I enter “smtp.gmail.com:587” as the smtp server address I get this error. Which I think means it actually tried to connect to gmail but was rejected.

    An Error Was Encountered
    Unable to send email at this time.
    
    220 mx.google.com ESMTP r37sm2966590wak.11 
    
    
    hello: 250-mx.google.com at your service, [MY_SERVER_IP]
    250-SIZE 35651584
    250-8BITMIME
    250-STARTTLS
    250 ENHANCEDSTATUSCODES
    
    email_failed_smtp_login
    
    from: 530 5.7.0 Must issue a STARTTLS command first. r37sm2966590wak.11
    
    email_smtp_error
    
    to: 530 5.7.0 Must issue a STARTTLS command first. r37sm2966590wak.11
    
    email_smtp_error
    
    data: 530 5.7.0 Must issue a STARTTLS command first. r37sm2966590wak.11
    
    email_smtp_error
    
    502 5.5.1 Unrecognized command. r37sm2966590wak.11 
    
    email_smtp_error
    
    email_send_failure_smtp

    If I enter “smtp.gmail.com:465” or “ssl://smtp.gmail.com:465” it loads for a while and eventually nginx gives me a 504 and no errors in php-fpm.log. I have openssl and php has it loaded as per the CI thread. 

    Any insight would be much appreciated.

  • #2 / Oct 07, 2010 3:21pm

    Ingmar's avatar

    Ingmar

    29245 posts

    I am afraid that’s not currently possible: Gmail will reject unencrypted connections which EE does not support at this point.

  • #3 / Oct 07, 2010 7:35pm

    humanhand

    2 posts

    That’s more than a little discouraging discouraging and seems to be the knee-jerk response to that question on this forum. 
    One last thing before I give up and go with sendmail or setup a different smtp.

    I noticed that if I set “SSL://smtp.gmail.com:645” as the smtp server address, when I try to send I get a long list of php errors in addition to the smtp ones below that.
    The first error is:

    A PHP Error was encountered
    Severity: Warning
    
    Message: fsockopen() [function.fsockopen]: unable to connect to SSL://smtp.gmail.com:25:645 (Unable to find the socket transport "SSL" - did you forget to enable it when you configured PHP?)
    
    Filename: libraries/Email.php
    
    Line Number: 1652

    From that I know that CI’s Email.php file tacks on the default port so I changed the default port to 645 in the file, removed it from the end of the server address, and purposely triggered the fsockopen error again to make sure that the right port was getting appended.  After that I set the smtp server address back to “smtp.gmail.com” and also tried putting the ssl in front, “ssl://smtp.gmail.com”
    They both give an fsockopen timeout error, slightly different from the one before:

    A PHP Error was encountered
    Severity: Warning
    
    Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:645 (Connection timed out)
    
    Filename: libraries/Email.php
    
    Line Number: 1652

    I can tell from my php_info and the fsockopen timeout error that openssl is loaded into my php setup.  I’m just a little confused since it’s possible to connect to smtp.gmail.com through codeigniter with ssl and EE 2.0 + uses codegniter to connect to send email, why can’t EE?

  • #4 / Oct 07, 2010 9:03pm

    humanhand

    2 posts

    UPDATE!

    I finally got it to work 😊
    I watched this net.tutsplus video on gmail smtp through codeigiter.  Fast forward to 5:10 and he talks about setting $newline or it won’t work.

    $newline = "\r\n";

     
    There were actual comments about this in the Email.php file, I just hadn’t taken notice of them until I saw the video.
    I was still getting a the fsockopen timeout error, after quite a bit more searching i found this codeigniter thread where the last reply said to set the $crlf as well.

    var $crlf = "\r\n"

    Once $crlf was set it worked!  Here is what the begining of my /codeigniter/libraries/Email.php looks like

    class CI_Email {
    
        var    $useragent        = "CodeIgniter";
        var    $mailpath        = "/usr/bin/sendmail";    // Sendmail path
        var    $protocol        = "sendmail";    // mail/sendmail/smtp
        var    $smtp_host        = "";        // SMTP Server.  Example: mail.earthlink.net
        var    $smtp_user        = "";        // SMTP Username
        var    $smtp_pass        = "";        // SMTP Password
        // VALUE I CHANGED
        var    $smtp_port        = "465";        // SMTP Port
        var    $smtp_timeout    = 5;        // SMTP Timeout in seconds
        var    $wordwrap        = TRUE;        // TRUE/FALSE  Turns word-wrap on/off
        var    $wrapchars        = "76";        // Number of characters to wrap at.
        var    $mailtype        = "text";    // text/html  Defines email formatting
        var    $charset        = "utf-8";    // Default char set: iso-8859-1 or us-ascii
        var    $multipart        = "mixed";    // "mixed" (in the body) or "related" (separate)
        var    $alt_message    = '';        // Alternative message for HTML emails
        var    $validate        = FALSE;    // TRUE/FALSE.  Enables email validation
        var    $priority        = "3";        // Default priority (1 - 5)
        // VALUE I CHANGED
        var    $newline        = "\r\n";        // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
        // VALUE I CHANGED
        var    $crlf            = "\r\n";        // The RFC 2045 compliant CRLF for quoted-printable is "\r\n".  Apparently some servers,
                                        // even on the receiving end think they need to muck with CRLFs, so using "\n", while

    With codeigniter’s Email.php properly configured, in the EE control panel I made sure the smtp server address was “ssl://smtp.gmail.com” after that I was able to send emails through gmail using the Communicate tool.


    In order for this to work you have to make sure your php has php_openssl enabled.  You can check this in the ExpressionEngine control panel at Tools > Utilities > PHP Info.  On that page just do a find ctrl+f/cmd+f for ‘openssl’ to see if it’s enabled.

    If it’s not enabled, when you try to send an email you will get an error like this:

    Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googmemail.com:465 (Unable to find the socket transport “ssl” - did you forget to enable it when you configured PHP?)


    A lot of windows users on the codeigniter forums had that issue, they worked around it by uncommenting this line from the php.ini file on their server.

    ;extension=php_openssl.dll

    I am very glad my hours of googling and trying a bunch of combinations of ports and smtp server address, actually paid off.  Also hope this answer helps anyone else trying to use gmail through smtp with ExpressionEngine.

    Good luck.

  • #5 / Oct 08, 2010 4:29am

    John Henry Donovan's avatar

    John Henry Donovan

    12339 posts

    humanhand,

    Thanks for sharing this detailed solution. Very helpful. Glad you are up and running again.Feel free to start a new thread if you have any more questions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases