简体   繁体   English

如何修改邮件正文-Mimekit邮件

[英]how modify message body - Mimekit Message

i'm using mimekit for receive and send mail for my project. 我正在使用mimekit接收和发送项目的邮件。 I'm sending received mails with some modifications (to & from parts). 我正在发送收到的邮件,并对其进行了一些修改(与各部分之间的修改)。 And now i need to modify in body section. 现在我需要在正文部分进行修改。 I'll replace specific word with asterix chars. 我将用asterix字符替换特定的单词。 Specific text different for every mail. 每个邮件的特定文本均不同。 Mail may be any format. 邮件可以是任何格式。 You can see i found what i want but i don't know how can i replace without any error? 您可以看到我找到了我想要的东西,但我不知道该如何替换而没有任何错误?

在此处输入图片说明

MimeMessage.Body is a tree structure, like MIME, so you'll have to navigate to the MimePart that contains the content that you want to modify. MimeMessage.Body是一个树结构,如MIME,因此您必须导航到包含要修改的内容的MimePart

In this case, since you want to modify a text/* MimePart , it will actually be a subclass of MimePart called TextPart which is what has the .Text property (which is writable). 在这种情况下,由于要修改text / * MimePart ,因此它实际上是MimePart的子类,称为TextPart ,它具有.Text属性(可写)。

I've written documentation on how to traverse the MIME structure of a message to find the part that you are looking for here: http://www.mimekit.org/docs/html/WorkingWithMessages.htm 我已经编写了有关如何遍历消息的MIME结构以在此处查找所需部分的文档: http : //www.mimekit.org/docs/html/WorkingWithMessages.htm

A very simple solution might be: 一个非常简单的解决方案可能是:

var part = message.BodyParts.OfType<TextPart> ().FirstOrDefault ();
part.Text = part.Text.Replace ("x", "y");

But keep in mind that that logic assumes that the first text/* part you find is the one you are looking for. 但是请记住,该逻辑假定您找到的第一个text / *部分就是您要寻找的部分。

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

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