smtp 0.0.9
SMTP library for D language
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
SMTP library for D
Current version: 0.0.3
Native SMTP client implementation in D language.
Tested with:
gdc-4.8
on Ubuntu 13.10dmd-2.065.0
on OS X 10.9.2
Features
SmtpClient
class that implements SMTP client.SmtpMessage
class that implements SMTP message fields storage.SSL/TLS
encryption support (viaOpenSSL
). Next encryption methods implemented:SSLv2
.SSLv23
.SSLv3
.
TODO
- Authentication support.
- Dedicated clients for popular mail providers.
- Unit-tests suite.
Installation
You can use smtp
library for D via dub
package manager.
For this, follow the next steps:
- Download dub from DLang site (if you still don't have it installed).
- Create your project (or use
dub.json
from your existing one). - Add
smtp
as a dependency:{ "dependencies": { "smtp": ">=0.0.3", } }
- Use dub to build project:
$ dub
to build with dependencies or
$ dub --force
after code update for rebuilding.
Usage
You 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-logged
Similar to
lowlevel
but also demonstrates possibities ofSmtpReply
structure to get and log messages from SMTP server.lowlevel-safe
Similar to
lowlevel-logged
but also shows how to check if errors happened during mail sending session.highlevel
Shows the simples chain of routines to send e-mail via unencrypted channel. Also you can find this example in this wiki page below.
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
.
Here's an example of high-level SmtpClient
API usage for sending sample email
either using open or encrypted channel.
#!/usr/bin/rdmd
import std.stdio;
import std.string;
import smtp.client;
import smtp.message;
import smtp.ssl;
void main() {
auto message = new SmtpMessage(
"[email protected]", // Sender (put some existing address here)
["[email protected]", "[email protected]"], // Recipients (put some existing addresses here)
"Test message subject", // Subject (topic)
"This is a test message body", // Body of the message
"" // Reply-to still does not work
);
auto client = new SmtpClient(
"localhost", // SMTP server host
25 // SMTP server port
);
client.connect(); // Perform connection
// Uncomment next line to start TLS-encrypted communication with server
// `startTls` method will work if and only if your SMTP server
// support SSL/TLS encryption.
//
// Good news is that `SmtpClient`
// analyzes replies for you and in case your server does not support
// encryption, the next code up to the end of the application
// will continue working through unencryted channel.
client.startTls(EncryptType.SSLv3);
if (client.send(message)) { // Check if message was sent successfully
writefln("Message: `%s` from <%s> to <%s> sent successfully!",
message.subject, message.sender, message.recipients);
} else {
writefln("Message was not sent for some reason");
}
client.quit(); // Tell SMTP server we're done with sending messages
client.disconnect(); // Making clean disconnect from server
}
- Registered by Rostyslav Dzinko
- 0.0.9 released 10 years ago
- SSPkrolik/smtp
- github.com/SSPkrolik/smtp
- MIT
- Copyright © 2014, Rostyslav Dzinko
- Authors:
- Dependencies:
- openssl
- System dependencies:
- OpenSSL 0.9.x or 1.0.x
- Versions:
-
0.3.0 2015-Jul-17 0.2.1 2015-Jul-15 0.2.0 2014-Apr-22 0.1.1 2014-Apr-12 0.1.0 2014-Apr-12 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
11258 downloads total
-
- Score:
- 1.2
- Short URL:
- smtp.dub.pm