2017 © Pedro Peláez
 

drupal-module drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

image

makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  • Monday, March 12, 2018
  • by pounard
  • Repository
  • 24 Watchers
  • 5 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Net SMTP

SMTP connector using Net_SMTP PEAR library., (*1)

Runtime configuration

Drupal mail system configuration

For your convenience, this module uses a specific Drupal mail system implementation that acts as a proxy which lets you use different formatter and mailer., (*2)

In order to use it, simply add to your settings.php file:, (*3)

$conf['mail_system'] = [
  'default-system' => '\\MakinaCorpus\\Drupal\\NetSmtp\\MailSystemProxy'
];

Then you can set the formatter this way:, (*4)

$conf['netsmtp_proxy'] = [
  'default' => 'MimeMailSystem',
];

If you need to specify specific formatters for other modules, you can use this variable the exact same way you would use the core 'mail_system' variable:, (*5)

$conf['netsmtp_proxy'] = [
  'default' => 'MimeMailSystem',
  'MYMODULE' => 'SomeOtherFormatter',
  'MYMODULE_MYMAIL' => 'YetAnotherFormatter',
];

And that's pretty much it., (*6)

SMTP configuration

At minima you would need to specify your SMTP server host:, (*7)

$conf['netsmtp'] = [
  'default' => [
    'hostname' => '1.2.3.4'
  ],
];

Hostname can be an IP or a valid hostname., (*8)

In order to work with SSL, just add the 'use_ssl' key with true or false., (*9)

You can set the port if you wish using the 'port' key., (*10)

If you need authentication, use this:, (*11)

$conf['netsmtp'] = [
  'default' => [
    'hostname' => 'smtp.provider.net',
    'username' => 'john',
    'password' => 'foobar',
  ],
];

And additionnaly, if you need to advertise yourself as a different hostname than the current localhost.localdomain, you can set the 'localhost' variable., (*12)

An complete example:, (*13)

$conf['netsmtp'] = [
  'default' => [
    'hostname'  => 'smtp.provider.net',
    'port'      => 465,
    'use_ssl'   => true,
    'username'  => 'john',
    'password'  => 'foobar',
    'localhost' => 'host.example.tld',
  ],
];

Note that for now this only supports the PLAIN and LOGIN authentication methods, I am definitly too lazy to include the Auth_SASL PEAR package as well., (*14)

Additionnaly, you can change the 'use_ssl' paramater to the 'tls' value instead, and hope for the best to happen, it should force the Net::SMTP library to do a TLS connection instead., (*15)

Advanced SMTP configuration

Additionnaly you can define a set of servers, for example if you need a mailjet or mandrill connection:, (*16)

$conf['netsmtp'] = [
  'default' => [
    'host' => '1.2.3.4',
    'ssl'  => true,
  ],
  'mailjet' => [
    'host' => '1.2.3.4',
    'ssl'  => true,
    'user' => 'john',
    'pass' => 'foobar',
  ],
];

You can then force mails to go throught another server than default by setting the 'smtp_provider' key in the Drupal $message array when sending mail., (*17)

Identifying the project

If you need to identify mails from various projects and environments you may use one of, or any combination of the two the following variables:, (*18)

$conf['netsmtp_project_name'] = 'My client business project';
$conf['netsmtp_project_env'] = 'staging';

Both are arbitrary values that could be set to any value without creating any side effect to mail being sent., (*19)

They both map to additional mail headers being added ot mails:, (*20)

  • X-Project-Name will contain the netsmtp_project_name value,
  • X-Project-Env will contain the netsmtp_project_env value.

There is one exception, if netsmtp_project_env begins with prod (case insensitive) then the X-Project-Env header will be dropped, and mail subject will be left untouched, no matter what other debug options are set., (*21)

Per default, setting the environment to anything else than a string begining with the prod substring, subject will be altered and will start with a string containing the project name and project environment. To deactivate this alteration, just set:, (*22)

$conf['netsmtp_project_expose_subject'] = false;

Add additional fixed headers to all outgoing mail

You may, for various purposes, need to add arbitrary platform driven headers to your mail, for this:, (*23)

$conf['netsmtp_additional_headers'] = [
    'X-FORWARD' => 'some value',
    'X-USERNAME' => '...',
    // ...
];

Overriding the proxy

Additionnaly, if you have specific business needs, you can override the proxy class, start by writing your own such as:, (*24)

use MakinaCorpus\Drupal\NetSmtp\MailSystemProxy

MyProxy extends MailSystemProxy
{
    // Do something
}

Then register it in any autoloader., (*25)

Then, tell the net-smtp module to use it instead of the stock provided one into your settings.php file:, (*26)

$conf['mail_system'] = [
  'default-system' => 'MyProxy'
];

Additional configuration

Per default this module uses the Drupal native function correctly encode mail subjects, if you use a formatter that does the job for you, set the netsmtp_subject_encode to false to deactivate this behavior:, (*27)

$conf['netsmtp_subject_encode'] = false;

Testing

Testing your Drupal configuration

This module provide a drush command to test your configuration:, (*28)

drush netsmtp-config-test mommy@myfamily.com

Please note that if you configured debug options, they will remain activated and mail will be routed accordingly if configured for., (*29)

Testing an SMTP connection

This module provide a drush command to test your SMTP connection:, (*30)

drush netsmtp-smtp-test \
    --hostname=mail.makina-corpus.net
    --port=465
    --use_ssl=tls
    --username=john.smith@example.com
    --password=ask
    mommy@myfamily.com

Only the hostname parameter is mandatory. If you set ask as the passowrd, drush will prompt it securely without displaying it., (*31)

Please note that all of the module configuration will be bypassed, if you configured mail catching, it will be skipped and the test mail will really be sent., (*32)

Debugging

Re-route all outgoing mail

This feature is useful when working in a development phase where you don't want mails to be sent to their real recipients. In order to activate it just set:, (*33)

$conf['netsmtp_catch'] = 'someuser@example.com';

Moreover, you can set multiple recipients:, (*34)

$conf['netsmtp_catch'] = [
  'user1@example.com',
  'user2@example.com',
  'user3@example.com',
  // ...
];

Be careful that this is a debug feature and the recipient user addresses won't be processed in any way, which means that you can set a mail address containing a ',' character, it won't be escaped., (*35)

Sent data dumping

Additionally you can enable a debug output that will dump all MIME encoded messages this module will send onto the file system. Just set:, (*36)

$conf['netsmtp_debug_mime'] = true;

And every mail will be dumped into the following Drupal temp folder:, (*37)

temporary://netsmtp/YYYY-MM-DD/

Additionnaly you can change the path using this variable:, (*38)

$conf['netsmtp_debug_mime_path'] = 'private://netsmtp';

Sent mail trace

This probably should belong to another module, but if you need extensive mail tracing logging, you can enable:, (*39)

$conf['netsmtp_debug_trace'] = true;

This will activate a hook_mail_alter() implementation that will log every mail activity sent by the plateform in a single file:, (*40)

temporary://netsmtp/netsmtp-trace-YYYY-MM-DD.log

In this file you'll find various internal Drupal modules information about the mails being sent, including the stack trace at the time the mail is beint sent., (*41)

Additionnaly you can change the path using this variable:, (*42)

$conf['netsmtp_debug_trace_path'] = 'private://netsmtp';

History

Drupal contrib already has a nice SMTP module called "SMTP" which can be found at the following URL:, (*43)

http://www.drupal.org/project/smtp

But in real life, this modules attempts to use the PHPMailer library to connect to the SMTP server, which can found at:, (*44)

https://github.com/PHPMailer/PHPMailer

If you look at it a bit more, you'll see that PHPMailer is not an SMTP connector, while it can, its main goal is to format the MIME messages for you., (*45)

Whenever you use Drupal with a module such as MIMEMail which can be found at:, (*46)

http://www.drupal.org/project/mimemail

you'll notice that your messages are already well formatted in a very precise and valid MIME enveloppe., (*47)

What happens behind this scenario is that the SMTP module needs to deconstruct the valid MIME encoded message in order to be able to use the PHPMailer API which then will attempt to rebuild a MIME message., (*48)

In real life, it does not, it does deconstrut your MIME encoded message, but in a very wrong way, and breaks it in a lot cases., (*49)

The Versions

12/03 2018

dev-master

9999999-dev http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2 GPL-2.0-or-later

The Requires

 

12/03 2018

2.1.0

2.1.0.0 http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2

The Requires

 

24/02 2017

2.0.2

2.0.2.0 http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2

The Requires

 

17/02 2017

2.0.1

2.0.1.0 http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2

The Requires

 

17/02 2017

2.0.0

2.0.0.0 http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2

The Requires

 

16/02 2017

1.0.x-dev

1.0.9999999.9999999-dev http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2

16/02 2017

1.0.0

1.0.0.0 http://github.com/makinacorpus/drupal-netsmtp

Drupal SMTP module based upon PEAR::Net_SMTP

  Sources   Download

GPL-2