This is possible and quite easy.
You can load mht file using:
IMail mht = new MailBuilder().CreateFromEmlFile("test.mht")
-or- mht data from memory:
IMail mht = ew MailBuilder().CreateFromEml(mht);
Then use IMail.ToBuilder method to create MailBuilder that can be used to modify the message:
IMail mht = new MailBuilder().CreateFromEmlFile("test.mht");
MailBuilder builder = mht.ToBuilder();
Remove headers defined in the mht file:
builder.From.Clear();
builder.To.Clear();
builder.Date = null;
You can also remove unnecessary headers directly from mht (before calling IMail.ToBuilder):
foreach (string header in mht.Headers.AllKeys)
{
if (header != "content-type")
mht.Headers.Remove(header);
}
MailBuilder builder = mht.ToBuilder();
Add correct headers:
builder.Subject = "The subject";
builder.From.Add(new MailBox("from@example.com"));
builder.To.Add(new MailBox("to@example.com"));
IMail email= builder.Create();
Finally you can send the message:
using(Smtp smtp = new Smtp())
{
smtp.Connect("smtp.example.com"); // or ConnectSSL for SSL
smtp.UseBestLogin("user", "password");
smtp.SendMessage(email);
smtp.Close();
}