vibe.d beta banner
get vibe.d

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 (
  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


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"] = " Contact Form <>";
	email.headers["From"] = "John Doe <>";
	email.headers["To"] = "Customer Support <>";
	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);

Sönke Ludwig


© 2012-2015 RejectedSoftware e.K.


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