toivo blog
web and other experiments
  • joomla
    • Validating Email Domain
    • Accessing External Databases
    • Fetching User Custom Fields in Joomla 4
    • Updating articles by deleted authors
    • how to list users with custom fields
    • finding the origin of cryptic messages
    • careful with uninstall
    • adding time to logged-In users
    • How to Debug Email in Joomla
    • Troubleshooting SMTP Connection in Joomla 3.x
    • Gmail as SMTP host in Joomla 3.x
  • hiking
    • viking way part 1
    • viking way part 2
  1. You are here:  
  2. Home
  3. Home
  4. Joomla

Gmail as SMTP server in Joomla 3.6.0

If your site used to send its emails through the Gmail SMTP server and stopped after the latest Joomla update, you can restore the sending by modifying one of Joomla files.  Modifying core files is not recommended but sometimes it has to be done as an emergency measure, until a permanent remedy has been implemented in the applications involved.

Versions of Joomla before 3.6.0 used to work with Gmail by using an app password, created from the 2-Step Verification page of Google Accounts at https://security.google.com/settings/security/apppasswords

After the update to version 3.6.0, the connection to smtp.gmail.com reports a failure in the verification of the server certificate:

[28-Jul-2016 09:54:34 UTC] PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:

error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in C:\www\joomla360\libraries\vendor\phpmailer\phpmailer\class.smtp.php on line 343

As instructed under "PHP 5.6 certificate verification failure" at https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting, you can set the Options parameter to bypass the verification of the server certificate.

The following code can be added as a workaround to the beginning of the function useSmtp() in the file libraries/joomla/mail/mail.php:

   // 20160729 workaround for certificate verification failure - ref. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    $this->SMTPOptions = array(
    'ssl' => array(
      'verify_peer' => false,
      'verify_peer_name' => false,
      'allow_self_signed' => true
    )
   );
    // 20160729 end
Details
Written by: Toivo Talikka
Category: Joomla
Published: 29 July 2016
Hits: 21472

Debugging SMTP Mail in Joomla 3.5.0

If you want to troubleshoot the SMTP connection to your outgoing mail server, you can do that by setting the existing debug option in the PHPMailer library, which executes the mail functions in Joomla.  This allows you to log the data, mail commands and the connection status to the PHP error log.

Please note that core modifications are not recommended and the following instructions assume that you revert the file to the original version as soon as possible.

Edit the file libraries/joomla/mail/mail.php and add the following lines to the beginning of the function useSmtp(), after line 467:

      // debug SMTPmailer
      // $this->SMTPDebug    = 3;        // output data, commands and connection status
      $this->SMTPDebug    = 4;           // low level data output, all messages
      $this->Debugoutput   = 'error_log';   // output to error log as configured in php.ini

That is all you need to do in Joomla 3.5.0.   There is a small additional modification you need to do for Joomla 3.4.8, documented in this article: Debugging SMTP Mail in Joomla 3.4.8

Once you run the mail function, for example by using Mass Mail to a small group of test users including yourself, you can see detailed messages in the PHP error log, for example this failed connection:

[19-Mar-2016 10:47:39 Europe/London] Connection: opening to smtp.gmail.com:587, timeout=10, options=array (  )

[19-Mar-2016 10:47:49 Europe/London]SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)

If the SMTP server responds and the connection succeeds, you can see the whole SMTP dialogue in the log file:

[23-Mar-2016 12:47:52 Europe/London] Connection: opening to smtp.gmail.com:587, timeout=300, options=array (  )

[23-Mar-2016 12:47:52 Europe/London] Connection: opened

[23-Mar-2016 12:47:52 Europe/London] SMTP -> get_lines(): $data is ""

[23-Mar-2016 12:47:52 Europe/London] SMTP -> get_lines(): $str is  "220 smtp.gmail.com ESMTP t7z282442970wjf.39 - gsmtp

Make sure that you go back to the original version of the file mail.php before the log file starts growing unnecessarily.

Details
Written by: Toivo Talikka
Category: Joomla
Published: 23 March 2016
Hits: 19595

Debugging SMTP Mail in Joomla 3.4.8

If you want to troubleshoot the SMTP connection to your outgoing mail server, you can do that by setting the existing debug option in the PHPMailer library, which executes the mail functions in Joomla.  This allows you to log the data, mail commands and the connection status to the PHP error log.

Please note that core modifications are not recommended and the following instructions assume that you revert the file to the original version as soon as possible.

These instruction are for Joomla 3.4.8.  If you already run Joomla 3.5.0, follow these instructions instead:  Debugging SMTP Mail in Joomla 3.5.0

Edit the file libraries/joomla/mail/mail.php and add the following lines to the beginning of the function useSmtp(), after line 467:

      // debug SMTPmailer
      // $this->SMTPDebug    = 3;        // output data, commands and connection status
      $this->SMTPDebug    = 4;           // low level data output, all messages
      $this->Debugoutput   = 'error_log';   // output to error log as configured in php.ini

In Joomla 3.4.8 you need to modify also the file libraries/vendor/phpmailer/phpmailer/class.smtp.php and replace line 190 with these lines:

        // if (is_callable($this->Debugoutput)) {
      // Avoid clash with built-in function names
        if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {

Once you run the mail function, for example by using Mass Mail to a small group of test users including yourself, you can see detailed messages in the PHP error log, for example this failed connection:

[19-Mar-2016 10:47:39 Europe/London] Connection: opening to smtp.gmail.com:587, timeout=10, options=array (  )

[19-Mar-2016 10:47:49 Europe/London]SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)

If the SMTP server responds and the connection succeeds, you can see the whole SMTP dialogue in the log file:

[23-Mar-2016 12:47:52 Europe/London] Connection: opening to smtp.gmail.com:587, timeout=300, options=array (  )

[23-Mar-2016 12:47:52 Europe/London] Connection: opened

[23-Mar-2016 12:47:52 Europe/London] SMTP -> get_lines(): $data is ""

[23-Mar-2016 12:47:52 Europe/London] SMTP -> get_lines(): $str is  "220 smtp.gmail.com ESMTP t7z282442970wjf - gsmtp

Make sure that you go back to the original version of the file mail.php before the log file starts growing unnecessarily.

Details
Written by: Toivo Talikka
Category: Joomla
Published: 22 March 2016
Hits: 17462

Gmail as SMTP server for Joomla

The alpha version of Joomla 3.2.0 is now available.  As usual, it is easy to install and it has new features.  

There was something I had wanted to test for some time: Gmail as the SMTP server. The Joomla documentation has instructions how to configure the mail settings but when I first tried it, the connection failed. I decided to configure the good old Telnet into my Windows machine so that I could test the SMTP connection manually. The TCP port 465 of the Gmail server responded, therefore the problem was somewhere else.

It occurred to me that I had started to use Google's 2-step authentication because I accessed Gmail from my Nokia Lumia phone. After the 2-step authentication was turned off, the problem disappeared and my WAMP server was able to send emails.

The 2-step authentication is an important security measure. When it was turned back on, I had to add a new password in the Gmail account settings and use that password as the application specific password in Joomla. The interesting thing was to realise that even though Google's instructions mention that the validity of the password does not depend on the blank spaces between the groups of four characters in the password, it actually did.  After the spaces were removed, the SMTP connection worked.

The instructions at https://docs.joomla.org have now been updated, based on these test results.

Details
Written by: Toivo Talikka
Category: Joomla
Published: 29 September 2013
Hits: 18181
  • joomla

Page 4 of 5

  • 1
  • 2
  • 3
  • 4
  • 5

Visitors

We had 81 visitors online in the last 2 days.