vibe.d beta banner
get vibe.d
0.10.1

Asynchronous I/O that doesn’t get in your way, written in D

Function sendMail

Sends an e-mail using the given settings.

void sendMail (
  in const(SMTPClientSettings) settings,
  Mail mail
) @safe;

The mail parameter must point to a valid Mail object and should define at least the headers "To", "From", Sender" and "Subject".

Valid headers can be found at http://tools.ietf.org/html/rfc4021

Example

The following example demonstrates the complete construction of a valid e-mail object with UTF-8 encoding. The Date header, as demonstrated, must be converted with the local timezone using the toRFC822DateTimeString function.

import vibe.inet.message;
import std.datetime;
void testSmtp(string host, ushort port){
	Mail email = new Mail;
	email.headers["Date"] = Clock.currTime(PosixTimeZone.getTimeZone("America/New_York")).toRFC822DateTimeString(); // uses UFCS
	email.headers["Sender"] = "Domain.com Contact Form <no-reply@domain.com>";
	email.headers["From"] = "John Doe <joe@doe.com>";
	email.headers["To"] = "Customer Support <support@domain.com>";
	email.headers["Subject"] = "My subject";
	email.headers["Content-Type"] = "text/plain;charset=utf-8";
	email.bodyText = "This message can contain utf-8 [κόσμε], and\nwill be displayed properly in mail clients with \\n line endings.";

	auto smtpSettings = new SMTPClientSettings(host, port);
	sendMail(smtpSettings, email);
}
// testSmtp("localhost", 25);
Authors

Sönke Ludwig

Copyright

© 2012-2015 Sönke Ludwig

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.