Download the PHP package makinacorpus/drupal-netsmtp without Composer

On this page you can find all versions of the php package makinacorpus/drupal-netsmtp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package drupal-netsmtp

Net SMTP

SMTP connector using Net_SMTP PEAR library.

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.

In order to use it, simply add to your settings.php file:

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

Then you can set the formatter this way:

$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:

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

And that's pretty much it.

SMTP configuration

At minima you would need to specify your SMTP server host:

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

Hostname can be an IP or a valid hostname.

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

You can set the port if you wish using the 'port' key.

If you need authentication, use this:

$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.

An complete example:

$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.

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.

Advanced SMTP configuration

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

$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.

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:

$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.

They both map to additional mail headers being added ot mails:

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.

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:

$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:

$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:

use MakinaCorpus\Drupal\NetSmtp\MailSystemProxy

MyProxy extends MailSystemProxy
{
    // Do something
}

Then register it in any autoloader.

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

$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:

$conf['netsmtp_subject_encode'] = false;

Testing

Testing your Drupal configuration

This module provide a drush command to test your configuration:

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

Testing an SMTP connection

This module provide a drush command to test your SMTP connection:

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

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.

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:

$conf['netsmtp_catch'] = '[email protected]';

Moreover, you can set multiple recipients:

$conf['netsmtp_catch'] = [
  '[email protected]',
  '[email protected]',
  '[email protected]',
  // ...
];

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.

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:

$conf['netsmtp_debug_mime'] = true;

And every mail will be dumped into the following Drupal temp folder:

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

Additionnaly you can change the path using this variable:

$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:

$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:

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.

Additionnaly you can change the path using this variable:

$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:

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:

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.

Whenever you use Drupal with a module such as MIMEMail which can be found at:

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

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

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.

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.


All versions of drupal-netsmtp with dependencies

PHP Build Version
Package Version
Requires pear/net_smtp Version ^1.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package makinacorpus/drupal-netsmtp contains the following files

Loading the files please wait ....