SMTP-module (Drupal)

Uit De Vliegende Brigade
Ga naar: navigatie, zoeken

Het is niet triviaal om vanuit Drupal 6 betrouwbaar email te versturen. Maar daar heeft de SMTP-module ivm. PHPMailer een oplossing voor. Voor Drupal 7 schijnt de situatie onvergelijkbaar veel beter te zijn, maar ehh, ook daar bestaat deze module voor, en lijkt daarbij niets aan bestaansrecht te hebben verloren.

Installatie smtp-module

drush -y en smtp

Installatie PHPMailer

  • Let op: Versie 2.2.1 is de laatste versie van PHPMailer die ondersteund wordt door de SMTP-module
  • Ik plaats degelijke libraries in sites/all/libraries.

In pseudo-code:

cd ~/in1 # Dit is een map voor inkomende bestanden op m'n server
wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz
tar -xzf v2.2.1.tar.gz # Ik geloof dat het resultaat een map genaamd PHPMailer is, of zoiets
cp -r ~/in1/PHPMailer /home/hostingaccount/site/public/sites/all/libraries
mv PHPMailer phpmailer # Bestandsnaam moet je aanpassen naar phpmailer

Configuratie

  • De module bestaat uit maar één onderdeel dat geactiveerd moet worden (Drush zoals hierboven gedaan, of via pagina Modules)
  • Er is maar één configuratie-pagina:
    Site configuration > SMTP Authentication Support
  • Je hebt verder niet direct met PHPMailer te maken.

Gebruik

Hier zie je oa. de SMTP-instellingen zoals ik die meestal nodig heb
  • Gebruik spreekt voor zich. Zie ook de afbeelding hiernaast
  • Eén aspect dat super is aan deze module: Je kunt de mailfunctie testen, zowel met als zonder SMTP-module: Op de SMTP-pagina heb je onderaan het scherm de mogelijkheid om een testmail te versturen. Als je (bovenaan de pagina) de SMTP-server hebt geactiveerd, wordt die test-email via PHPMailer verstuurd. Als de SMTP-sever niet is geactiveerd, wordt er gemailed via de standaard-Drupal methode.

WSOD

Als de PHPMailer-library niet correct is geïnstalleerd, geeft dan al snel een WSOD, en dit is wat het PHP-logboek er van vindt:

[17-Sep-2015 16:27:44 Europe/Berlin] PHP Fatal error:  Class 'SMTP' not found in 
/hier/daaro.nl/public/sites/all/modules/smtp/phpmailer/class.phpmailer.php on line 1302

Casus sep. 2015: SMTP-module met succes geïnstalleerd (1)

Met deze instellingen heb ik testmails kunnen sturen, zonder foutmelding:

  • Email-Only-abonnement TransIP
  • Poort 465
  • SSL

Let op: Als er debugging-info wordt gestuurd, wil dat niet automatisch zeggen dat er iets mis is. In het bijzonder als je de module aanzet, komt er een enorme hoeveelheid debug-info voorbij. Bv.:


SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "220 submission2.mail.transip.nl ESMTP " 
SMTP -> get_lines(): $data is "220 submission2.mail.transip.nl ESMTP " 
SMTP -> FROM SERVER: 220 submission2.mail.transip.nl ESMTP 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250-submission2.mail.transip.nl " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl " 
SMTP -> get_lines(): $str is "250-PIPELINING " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING " 
SMTP -> get_lines(): $str is "250-SIZE 40000000 " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 " 
SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN " 
SMTP -> get_lines(): $str is "250-AUTH=PLAIN LOGIN " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN " 
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES " 
SMTP -> get_lines(): $str is "250-8BITMIME " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME " 
SMTP -> get_lines(): $data was "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME " 
SMTP -> get_lines(): $str is "250 DSN " 
SMTP -> get_lines(): $data is "250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN " 
SMTP -> FROM SERVER: 250-submission2.mail.transip.nl 250-PIPELINING 250-SIZE 40000000 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6 " 
SMTP -> get_lines(): $data is "334 VXNlcm5hbWU6 " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 " 
SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "235 2.7.0 Authentication successful " 
SMTP -> get_lines(): $data is "235 2.7.0 Authentication successful " 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250 2.1.0 Ok " 
SMTP -> get_lines(): $data is "250 2.1.0 Ok " 
SMTP -> FROM SERVER: 250 2.1.0 Ok 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250 2.1.5 Ok " 
SMTP -> get_lines(): $data is "250 2.1.5 Ok " 
SMTP -> FROM SERVER: 250 2.1.5 Ok 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "354 End data with . " 
SMTP -> get_lines(): $data is "354 End data with . " 
SMTP -> FROM SERVER: 354 End data with . * phpmailer downloaden: <code>wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz</code>

SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 3nH3Nx2Xn0z1b7X " 
SMTP -> get_lines(): $data is "250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 3nH3Nx2Xn0z1b7X " 
SMTP -> FROM SERVER: 250 2.0.0 from MTA(smtp:[127.0.0.1]:10025): 250 2.0.0 Ok: queued as 3nH3Nx2Xn0z1b7X 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "221 2.0.0 Bye " 
SMTP -> get_lines(): $data is "221 2.0.0 Bye " 
SMTP -> FROM SERVER: 221 2.0.0 Bye 

Casus sep. 2015: SMTP-module met succes geïnstalleerd (2)

In pseudo-code:

drush -y smtp
mkdir ..sites/all/libraries
cd ../sites/all/libraries
wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz
tar -xzf v2.2.1.tar.gz
mv PHPMailer-2.2.1/ phpmailer

Casus sep. 2015: In één keer 11 websites bijwerken

#!/bin/bash

url[1]="boorhouders-online.nl"
url[2]="carbonbrushes-online.com"
url[3]="drijfriemen.nl"
url[4]="escobillas-maquinas.es"
url[5]="kohlebuersten-werkzeuge.de"
url[6]="paalhouders.nl"
url[7]="riemtechniek.nl"
url[8]="slangenboren-online.nl"
url[9]="slijpmachines-online.nl"
url[10]="tuinbeslag-online.nl"
url[11]="wespenvangers.nu"

# Constanten
#
pad_stam="/home/hosting-account/public/"

for i in `seq 1 11`;
   do
      pad=$pad_stam${url[$i]}"/public"
      echo -e "\n\n###################### "${url[$i]}"\n"
      drush -r $pad -y en smtp
      mkdir $pad"/sites/all/libraries"
      cp -r /home/hostingaccount/in4/phpmailer $pad"/sites/all/libraries"
      drush -r $pad -y en permissions_api     # Permissions-API gebruikt om rol 'Beheerder' toegang te geven tot deze module
      drush -r $pad perm-grant --all-modules --roles="Beheerder"
      drush -r $pad -y dis permissions_api    # En nu mag-ie weer uit.
   done
fi

Casus feb. 2016: Voorzieningen voor een tijdelijke site

Ook voor een ontwikkel- of externe testsite, is het prettig als-ie kan emailen. Deze site was gehost op een subdomein. Ik heb het emailaccount gebruikt dat hoorde bij het betreffende hoofddomein.

Bronnen

php's mail()

Externe mailserver

Drupal SMTP-module

PHPMailer

PHPMailer - SMTP-class-foutmelding

Appendix: smtp-README.txt

SMTP Authentication Support module for Drupal 6.x.
This module adds SMTP functionality to Drupal.

REQUIREMENTS
------------
* Access to an SMTP server 
* PHP version 4.0.0 and up.
* The following PHP extensions need to be installed: ereg, hash, date & pcre.
* The PHPMailer package from Codeworx Tech., which can be found here:
  http://phpmailer.worxware.com/index.php?pg=phpmailer
  http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/

  The latest version supported is 2.2.1

* Optional: To connect to an SMTP server using SSL, you need to have the
  openssl package installed on your server, and your webserver and PHP
  installation need to have additional components installed and configured.

INSTALL INSTRUCTIONS
--------------------
See INSTALL.txt

NOTES
-----
This module sends email by connecting to an SMTP server.  Therefore, you need
to have access to an SMTP server for this module to work.

Drupal will often use the email address entered into Administrator -> Site
configuration -> E-mail address as the from address.  It is important for
this to be the correct address and some ISPs will block email that comes from
an invalid address.

Because this module uses the PHPMailer package, it is rather large and may
cause PHP to run out of memory if its memory limit is small.

Connecting to an SMTP server using SSL is possible only if PHP's openssl
extension is working.  If the SMTP module detects openssl is available it
will display the options in the modules settings page.

Sending mail to Gmail requires SSL or TLS.

Appendix: SMTP-INSTALL.txt

NOTE: See the REQUIREMENTS in the README.txt file.

INSTALLATION INSTRUCTIONS
-------------------------
1.  Copy the files included in the tarball into a directory named "smtp" in
    your Drupal sites/all/modules/ directory.

2.  Download the PHPMailer package (the URL is listed in REQUIREMENTS section
    of the README.txt file). Unarchive the file and name the resulting directory
    phpmailer

3.  You can then put the library in any of 3 places:
    a)  sites/all/libraries (ie. sites/all/libraries/phpmailer) **recommended**
    b)  path/to/smtp  (ie. sites/all/modules/smtp/phpmailer)
    c)  Install the libraries module and place the library at a location where
        library module can find it.  (normally sites/all/libraries)

4.  Apply the adequate patch inside the phpmailer directory (check Drupal docs
    on how to apply patches).

5.  Login as site administrator.

6.  Enable the SMTP Authentication Support module on the Administer -> Site
    building -> Modules page.

7.  Fill in required settings on the Administer -> Site configuration -> SMTP
    Authentication Support page.

8.  Enjoy.