简体   繁体   中英

Mailkit MimeKit.MimeMessage error: Unknown initialization parameter: System.Byte[]

I want to forward an email after add some comment to that. original email saved as eml file so first i load that file and then add my comment to body or attach some new files and then resend email to new email address.

var mail = new MimeKit.MimeMessage();
var file = System.IO.File.ReadAllBytes("sample.eml"));
var orgMessage = new MimeKit.MimeMessage(file);

var builder = new MimeKit.BodyBuilder();
builder.TextBody = "user comment";
builder.Attachments.Add(new MimeKit.MessagePart { Message = orgMessage });
mail.Body = builder.ToMessageBody();

First of all in line 3 i get this error: Unknown initialization parameter: System.Byte[]

Second I read this great answer Forward email using MailKit (C#) and what is resent parameters for? if i set them my comment on forwarded email not set? and that email resent clearly without any change?

Unknown initialization parameter: System.Byte[]

This means that there is no MimeMessage constructor that takes a byte[] parameter.

In other words, you can't do this:

var file = System.IO.File.ReadAllBytes("sample.eml"));
var orgMessage = new MimeKit.MimeMessage(file);

The correct way to load a message from a file is to do this:

var orgMessage = MimeMessage.Load ("sample.eml");

Second I read this great answer Forward email using MailKit (C#) and what is resent parameters for? if i set them my comment on forwarded email not set? and that email resent clearly without any change?

The MimeMessage.Resent* properties are used only when forwarding a message without attaching it to a new message.

You need to pick only 1 of the 3 solutions in the answer of mine that you linked to.

If you are going to attach the original message (like you are doing), then you SHOULD NOT use the Resent properties of the MimeMessage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM