Mailkit: send attachement from array

Created on 1 Jan 2017  路  3Comments  路  Source: jstedfast/MailKit

I am testing .Net Core MVC, which does not support System.Net.Mail, Mailkit, works well but can't figure out how to send attachments that I have stored in my database as binary. I used the following in MVC 5:

var mail = new MailMessage();
     mail.Attachments.Add(new Attachment(new MemoryStream(attachment), 
     attachmentName, attachmentType));

I would appreciate your suggestions. Thank you

question

Most helpful comment

This is probably the easiest solution:

var message = new MimeMessage ();
var builder = new BodyBuilder ();

builder.Attachments.Add (attachmentName, attachment, ContentType.Parse (attachmentType));

message.Body = builder.ToMessageBody ();

This assumes that attachmentName and attachmentType are strings while attachment is a byte[].

All 3 comments

This is probably the easiest solution:

var message = new MimeMessage ();
var builder = new BodyBuilder ();

builder.Attachments.Add (attachmentName, attachment, ContentType.Parse (attachmentType));

message.Body = builder.ToMessageBody ();

This assumes that attachmentName and attachmentType are strings while attachment is a byte[].

Thank you

Thank man!

Was this page helpful?
0 / 5 - 0 ratings