Skip to content

Commit

Permalink
Merge pull request #751 from etcimon/smtp-examples
Browse files Browse the repository at this point in the history
Added basic SMTP documentation and examples
  • Loading branch information
s-ludwig committed Aug 3, 2014
2 parents 8e5a00a + c8b442a commit 4006dce
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion source/vibe/mail/smtp.d
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ final class Mail {
}

/**
Sends am email using the given settings.
Sends an email using the given settings and mail. Your message must contain a
valid $(D Mail) object and should define the headers "To", "From", Sender" and "Subject".
Valid headers can be found at http://tools.ietf.org/html/rfc4021
*/
void sendMail(SMTPClientSettings settings, Mail mail)
{
Expand Down Expand Up @@ -201,6 +203,30 @@ void sendMail(SMTPClientSettings settings, Mail mail)
expectStatus(conn, SMTPStatus.serviceClosing, "QUIT");
}

/**
* 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 $(D toRFC822DateTimeString) function.
*/
unittest {
import vibe.inet.message;
import std.datetime;
void testSmtp(string host, ushort port){
Mail email = new Mail;
email.headers["Date"] = Clock.currTime(TimeZone.getTimeZone("America/New_York")).toRFC822DateTimeString(); // uses UFCS
email.headers["Sender"] = "Domain.com Contact Form <[email protected]>";
email.headers["From"] = "John Doe <[email protected]>";
email.headers["To"] = "Customer Support <[email protected]>";
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);
}

private void expectStatus(InputStream conn, int expected_status, string in_response_to)
{
// TODO: make the full status message available in the exception
Expand Down

0 comments on commit 4006dce

Please sign in to comment.