简体   繁体   English

Mailkit MimeKit.MimeMessage错误:未知的初始化参数:System.Byte []

[英]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. 原始电子邮件另存为eml文件,因此我首先加载该文件,然后将我的评论添加到正文或附加一些新文件,然后将电子邮件重新发送到新的电子邮件地址。

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[] 首先,在第3行中,我得到以下错误:未知的初始化参数:System.Byte []

Second I read this great answer Forward email using MailKit (C#) and what is resent parameters for? 其次,我读了这个很棒的答案使用MailKit(C#)转发电子邮件,重发参数有什么用? if i set them my comment on forwarded email not set? 如果我将它们设置为我对转发电子邮件的评论未设置? and that email resent clearly without any change? 并清楚地重新发送了该电子邮件,没有任何更改?

Unknown initialization parameter: System.Byte[] 未知的初始化参数:System.Byte []

This means that there is no MimeMessage constructor that takes a byte[] parameter. 这意味着没有MimeMessage构造函数采用byte[]参数。

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? 其次,我读了这个很棒的答案使用MailKit(C#)转发电子邮件,重发参数有什么用? 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. MimeMessage.Resent*属性仅在转发邮件而不将其附加到新邮件时使用。

You need to pick only 1 of the 3 solutions in the answer of mine that you linked to. 您只需在链接的我的答案中选择3个解决方案之一。

If you are going to attach the original message (like you are doing), then you SHOULD NOT use the Resent properties of the MimeMessage . 如果您要附加原始消息(如您​​所做的那样),则不应使用MimeMessageResent属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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