Email versturen (Drupal): verschil tussen versies
Regel 315: | Regel 315: | ||
== Casus sep. 2015: SMTP-module met succes geïnstalleerd (2) == | == Casus sep. 2015: SMTP-module met succes geïnstalleerd (2) == | ||
− | + | In pseudo-code: | |
<pre> | <pre> | ||
Regel 324: | Regel 324: | ||
tar -xzf v2.2.1.tar.gz | tar -xzf v2.2.1.tar.gz | ||
mv PHPMailer-2.2.1/ phpmailer | mv PHPMailer-2.2.1/ phpmailer | ||
− | + | </pre> | |
− | |||
− | |||
== Bronnen == | == Bronnen == |
Versie van 18 sep 2015 16:38
In diverse situaties verstuurt Drupal e-mail, bv. order-bevestigingen door Übercart of account-bevestigingen. Dat gaat niet altijd vlekkeloos. Het fundamentele probleem is het gebruik van de php-functie mail()
, die alleen gebruik kan maken van een locale Sendmail-instantie. Er zijn gelukkig oplossingen.
Vanaf Drupal 7 speelt dit probleem niet meer, omdat er standaard gebruik wordt gemaakt van PHPMailer()
.
Het probleem: mail()
Drupal gebruikt een wrapper om de PHP-functie mail()
:
bool mail(string $to, string $subject, string $message [, string $additional_headers [, string $additional_parameters ]] )
mail
functioneert als een mailclient voor de locale mailserver. Dus een mailserver die op die machine draait. Meer over de betreffende mailserver kun je achterhalen met phpinfo()
. Mail kan alleen overweg met een locale mailserver, en schijnt vrij beroerd te werken. Problematischer: Zover ik weet, kan het alleen overweg met één domein per webserver. Als er meerdere domeinen op een webserver geconfigureerd zijn, moet je gaan spoofen. En veel spamfilters vinden het niet leuk als je dat doet.
Mail-headers
Dit is een header van zo'n email. Deze email is verstuurd uit naam van domein koolborstels-online.nl. Dit domein staat op een VPS welke gedeeld wordt met een aantal andere domeinen. De server-ID is blijkbaar dvb-01.colo.transip.net
:
Delivered-To: jstrompf@gmail.com Received: by 10.37.93.8 with SMTP id r8csp319478ybb; Thu, 17 Sep 2015 02:49:46 -0700 (PDT) X-Received: by 10.194.122.132 with SMTP id ls4mr59057102wjb.130.1442483385893; Thu, 17 Sep 2015 02:49:45 -0700 (PDT) Return-Path: <www-data@dvb-01.colo.transip.net> Received: from plesk2.duocast.net (plesk2.duocast.net. [83.137.149.10]) by mx.google.com with ESMTPS id lm5si2956402wjc.18.2015.09.17.02.49.45 for <jstrompf@gmail.com> (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 02:49:45 -0700 (PDT) Received-SPF: neutral (google.com: 83.137.149.10 is neither permitted nor denied by best guess record for domain of www-data@dvb-01.colo.transip.net) client-ip=83.137.149.10; Authentication-Results: mx.google.com; spf=neutral (google.com: 83.137.149.10 is neither permitted nor denied by best guess record for domain of www-data@dvb-01.colo.transip.net) smtp.mailfrom=www-data@dvb-01.colo.transip.net Received: by plesk2.duocast.net (Postfix, from userid 30) id 2CA16E0856B; Thu, 17 Sep 2015 11:42:28 +0200 (CEST) DomainKey-Status: no signature X-Original-To: jeroen@strompf.com Delivered-To: jeroen@strompf.com Received: from dvb-01.colo.transip.net (unknown [IPv6:2a01:7c8:aaae:5c7:1a4:4066:b193:bc1]) by plesk2.duocast.net (Postfix) with ESMTP id 01B5DE0852F for <jeroen@strompf.com>; Thu, 17 Sep 2015 11:42:27 +0200 (CEST) Received-SPF: none (no valid SPF record) Received: by dvb-01.colo.transip.net (Postfix, from userid 33) id 829202E728A; Thu, 17 Sep 2015 11:48:45 +0200 (dvb-01.colo.transip.netCEST) To: jeroen@strompf.com Subject: Uw bestelling bij Koolborstels-online.nl X-PHP-Originating-Script: 1000:mail.inc MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8Bit X-Mailer: Drupal Errors-To: info@koolborstels-online.nl Sender: info@koolborstels-online.nl From: "Koolborstels-online.nl" <info@koolborstels-online.nl> Message-Id: <20150917094845.829202E728A@dvb-01.colo.transip.net> Date: Thu, 17 Sep 2015 11:48:45 +0200 (CEST)
Troubleshooting
Begin bij het logboek
Je weet wel:
Drupal: Reports > Recent log entries
Als deze entry er niet staat, moet je wellicht module Database logging en/of Syslog aanzetten.
Het logboek houdt alleen bij of email met success is afgeleverd bij de mailserver. Dat zegt dus niet of de mailserver de mail met succes heeft kunnen versturen.
Anders kan het PHP-logboek ook helpen:
less /var/log/php/error.log
Controleer de afzender (site information)
In de voortdurende strijd tegen spam, controleren veel ontvangende mailservers of de verzendende mailserver wel echt bestaat. Dat kan een probleem zijn, bv. als de betreffende website op een ontwikkelserver staat zonder domeinnaam, maar met alleen een IP-adres. Of als de site een echte naam heeft, maar op een ontwikkelserver draait, zonder die domeinnaam.
De afzender staat geconfigureerd onder Site information.
Übercart? Controleer de afzender!
In november 2012 had ik bij het klonen van een Übercart-site vergeten om het afzender-e-mailadres te veranderen. Bevestigingen van nieuwe accounts werden dus wel goed verzonden, maar orderbevestigingen niet.
In Drupal 6 moet je de afzender op twee of drie plekken aanpassen onder Conditionele acties.
Externe SMTP-server gebruiken: Mogelijkheden
Hierboven werd mail()
genoemd, en de tekortkomingen die het heeft. Verzending via een externe mailserver, zou een universele oplossing zijn. Mogelijkheden:
- nail()
- Swiftmailer
- PHPMailer eventueel icm. de Drupal SMTP-module
Maar hoe integreer je dit met Drupal of Übercart?
Externe SMTP-server gebruiken: SMTP-module + PHPMailer
Dit lijkt de meest voor de handliggende oplossing te zijn. Zie verderop onder casussen voor restultaten.
Casus mei 2012: Storing order-notificatie-e-mails (Drupal 6)
Dit betreft een storing waarbij de foutmelding gemeld werd.
Casus nov. 2012: Geen email na klonen webwinkel (Drupal 6 & Übercart)
Zie beschrijving in een eerder hoofdstuk.
Casus april 2015: Geen email na migratie (Drupal 6 & Übercart)
Dit probleem trad op na migratie van een Übercart-site naar een eigen VPS icm. een Email-Only-abonnement van TransIP. In de praktijk blijk je niet naar jezelf te kunnen emailen. Ik heb hier contact over gehad met TransIP, maar dat heeft tot op heden weinig opgeleverd.
Casus lente & zomer 2015: Vaak geen email vanuit Übercart
Probleem & aanvullende gegevens
Bij een bepaalde Drupal 6-webwinkel ontvangen klanten vaak geen orderbevestiging:
- Drupal-log vermeldt geen problemen
- PHP-log vermeldt geen problemen
- In het bijbehorende email-only-abonnement staat spamfiltering op z'n laagst, nog afgezien dat spamfiltering betrekking heeft op binnenkomende email, en niet op uitgaande email
- Bij een test op 5 augustus kreeg ik zelf wel gewoon een orderbevestiging
- Er komt geen email met fouten retour.
Overgebleven mogelijke oorzaken
- Kloppen de email-gerelateerde instellingen op deze Drupal-site?
- Is het SPF-record correct ingevuld?
Casus herfst 2015: Geen orderbevestigingen
Probleem
De orders van een aantal webwinkels komen niet meer aan in een Gmail-account dat gebruikt wordt voor monitoring.
Aanvullende gegevens
- Dit betreft meerdere webwinkels, terwijl er niets aan die webwinkels is veranderd
- Het probleem treedt op op meerdere computers
- De enige gemeenschappelijke factor: Gebruik Gmail
- Geen orders in de spambox
Mogelijke oorzaken
- Gmail past voortdurend spaminstellingen aan. Dingen die voor Gmail overduidelijk spam zijn, belanden niet in de spambox, maar worden direct verwijderd
- Er wordt gebruik gemaakt van generieke mailserver-instellingen. Dat geeft een mismatch met de domeinnamen waarvoor gemailed wordt. Dat wordt al snel als spam aangemerkt.
Casus sep. 2015 (1): Drupal SMTP-module in gebruik nemen
Ik volg deze handleiding:
- Installeer Drupal-module SMTP Authentication Support:
drush -y en smtp
- Maak de smtp-module-map de werkmap
- Download PHPMailer:
wget https://github.com/Synchro/PHPMailer/archive/master.zip
- Pak PHPMailer uit:
unzip master.zip
. Nu staat het in een submapPHPMailer-master
. Da's precies goed - Verander de naam van de PHPMailer-map:
mv PHPMailer-master phpmailer
- Configureer de module onder
Site configuration > SMTP Authentication Support
Foutmelding: Class 'SMTP' not found in ... smtp/phpmailer/class.phpmailer.php on line 1291
- Deze klasse is gedefineerd in
modules/smtp/phpmailer/class.smtp.php
maar wordt blijkbaar niet geladen - Het gaf nog WSOD's ook:
[16-Sep-2015 17:44:10 Europe/Berlin] PHP Fatal error: Class 'SMTP' not found in /home/hiero/public/daaro.nl/public/sites/all/modules/smtp/phpmailer/class.phpmailer.php on line 1291
Casus sep. 2015 (2): Drupal SMTP-module in gebruik nemen
Installatie-procedure in pseudo-code:
drush -y en smtp cd ~/in2 wget https://github.com/Synchro/PHPMailer/archive/master.zip unzip master.zip cd .../sites/all/modules/smtp mkdir phpmailer cd phpmailer cp -r ~/in2/PHPmailer/* .
Configuratie
Site configuration > SMTP Authentication Support
Goede testmogelijkheden
Het is erg handig dat je vanaf de configuratiepagina test-emails kunt sturen.
WSOD: Library niet gevonden
Bij het enablen van de module, kreeg ik een WSOD, die onderstaande regel in het logboek achterliet.
Casus Sep. 2015: Foutmelding: Class 'SMTP' not found
Foutmelding
[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
Aanvullende gegevens
- De Drupal SMTP-module ondersteunt PHPMailer tot en met versie 2.2.1
- Versie PHPMailer: 5.2.13
- PHPMailer ondersteunt de Libraries API sinds versie 3.x
Mogelijke oorzaken
- Het mechanisme om de betreffende klasse-definitie te laden, ontbreekt
- Ik heb de library niet op de juiste plek gezet: De handleiding die ik volgde, was nogal out. Deze posting uit 2006 zegt: sites/all/libraries/phpmailer
Conclusie
readme.txt en install.txt lezen.
Casus sep. 2015: SMTP-module met succes geïnstalleerd (1)
- phpmailer downloaden:
wget https://github.com/PHPMailer/PHPMailer/archive/v2.2.1.tar.gz
- Zie Readme- en Install-handleidingen in de appendix
- Ik kon geen patch vinden.
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
Bronnen
- http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_send/6 - De API die mailen verzorgd
- http://drupal.org/node/356525 - Reroute Email Module om e-mailen te testen
- http://drupal.org/node/201981 - Aardig overzicht van verschillende debug-mogelijkheden
- http://www.ubercart.org/forum/support/9146/after_completing_order_unable_send_email_please_contact_site_admin_if_problem_per
- http://www.ubercart.org/docs/user/8590/email_notifications
- http://www.ubercart.org/docs/user/305/notification_settings
php's mail()
Externe mailserver
- http://www.google.com/search?q=drupal+use+external+smtp+server
- http://www.tonyrocks.com/index.php/blogging/content-management-systems/configuring-drupal-to-use-an-external-smtp-server/
- http://stackoverflow.com/questions/6573511/how-do-i-specify-to-php-that-mail-should-be-sent-using-an-external-mail-server
- http://www.symphonythemes.com/drupal-blog/configure-drupal-smtp-gmail - Concrete implementatie
Drupal SMTP-module
PHPMailer
- https://github.com/PHPMailer/PHPMailer/releases/tag/v2.2.1 - Nieuwste ondersteunde versie
PHPMailer - SMTP-class-foutmelding
- https://www.google.nl/search?q=drupal+6+smtp+class+%27smtp%27+not+found+in+class.phpmailer.php
- https://github.com/PHPMailer/PHPMailer/issues/113
- https://www.drupal.org/node/1982536 - Fatal error: Class 'PHPMailer' not found in C
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.