Native synchronous SMTP client implementation in D language. Get at official Dub repository: code.dlang.org
Tested with:
dmd-2.066.0
stable on Ubuntu 15.04 Vivid VervetSmtpClient
.MailSender
.GMailSender
(ssl version only)SSL/TLS
encryption support (via OpenSSL
). Next encryption methods implemented:
SSLv2
SSLv23
SSLv3
TLSv1
PLAIN
LOGIN
You can use smtp
library for D via dub
package manager.
For this, follow the next steps:
dub.json
from your existing one).Add smtp
as a dependency:
{
"dependencies": {
"smtp": ">=0.1.1",
}
}
Use dub to build smtp library:
without SSL/TLS support
$ dub
or with SSL/TLS support:
$ dub -c ssl
or with SSL/TLS support when OpenSSL is prebuilt without SSLv2 support:
$ dub -c ssl-no-ssl2
To chose right smtp building configuration for your project use subConfigurations
setting in
your project's dub.json
:
{
"subConfigurations": { "smtp": "no-ssl" }
}
Available configurations are:
no-ssl
by defaultssl
to build with OpenSSL
supportYou can find low-level API usage example projects in examples
folder:
lowlevel
Shows the simplest chain of routines to send e-mail message via
unencrypted channel.
lowlevel-tls
Shows the simplest chain of routines to send e-mail message via
encrypted channel. Note: if you want to use SSLv2 encryption type for some
reason, you have to change "smtp": "ssl-no-ssl2"
to "smtp": "ssl2"
in
subConfiguration
section of the example's dub.json file.
sender
Shows how to authenticate and send a message using high-level API via
MailSender
class: connect
, authenticate
, send
, and quit
methods.
MailSender
high-level methods provide thread-safety.
attachments
Shows how to send messages with attachments using MailSender
class via
attach
method and SmtpAttachment
structure.
You can enter folder examples/<example-project-name>
and perform $ dub
in order
to run and test example.
If you're a Linux
or OS X
user, you can use standard sendmail
utility
to get SMTP server up and running on your local host. For that just open
new terminal tab or window and type sendmail
.
If you want to test encrypted client, you can use smtp.gmail.com:587
along
with TLSv1
encryption method. Obviously this works with ssl
configuration
of smtp library only.