0 votes

I need to create multiple and nested mimeparts. I can do that via Java Mail. Is it possible in Mail.dll? If so, how can i do that?

by

1 Answer

0 votes

You can create any MimeDocument using Mail.dll. The question is: do you really need to create it yourself?

MailBuilder class creates an email message that has correct MIME document. It handles alternatives, mixed, and related multipart objects. It handles signing and encryption.

For example when adding attachment to HTML message, appropriate multipart/mixed and multipart/alternative parts are created automatically:

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@mail.com", "Alice"));
builder.To.Add(new MailBox("bob@mail.com", "Bob"));
builder.Subject = "Test";
builder.Text = "This is a message.";
builder.Html = "This is a <strong>message</strong>.";

MimeData attachment = builder.AddAttachment(@"../image.jpg");

IMail email = builder.Create();

using (Smtp smtp = new Smtp())
{
    smtp.Connect("server.example.com");   // or ConnectSSL for SSL
    smtp.UseBestLogin("user", "password");   // remove if not needed

    smtp.SendMessage(email);

    smtp.Close();
}
by (297k points)
...