+2 votes

i have a question for you:

i need to add to my emails (created by my software) a "X-mailer header", inserting in it a string value which identify my software for the receiver. I found the code to add an header to the headers collection, but could not find a way to specify the "X-mailer header" (Which is supposed to be only one, not a collection". Can you guys tell me how to do it with your lib?

P.S. Thanks in advance for your support, every time i change workplace i force my new boss to purchase your lib since is simply awesome, and the support is awesome too. Great job, keep working like that!

by

1 Answer

0 votes
 
Best answer

Here's the code that adds "X-Mailer" header to the email message:

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@example.com"));
builder.To.Add(new MailBox("bob@example.com"));
builder.Subject = "hello";
builder.Text = "body";
builder.AddCustomHeader("X-Mailer", "my-mailer 1.0");

IMail mail = builder.Create();
Assert.AreEqual("my-mailer 1.0", mail.Headers["x-mailer"]);

You can use following code to see how your email looks like:

Console.WriteLine(Encoding.ASCII.GetString(mail.Render()));

This is how the rendered email looks like:

Content-Type: text/plain;
 charset="utf-8"
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Date: Fri, 23 Oct 2015 12:46:03 +0200
Message-ID: <763cab77-7f0d-49f3-9126-506d9abc96b1@mail.dll>
Subject: hello
From: <alice@example.com>
To: <bob@example.com>
X-Mailer: my-mailer 1.0

body

Invoking MailBuilder.AddCustomHeader multiple times with the same key, doesn't override previous values - this way you can add same key (with different values) several times.

by (297k points)
...