gpt4 book ai didi

c# - 使用 C# 编辑 Outlook.MailItem 的 RTFBody

转载 作者:太空宇宙 更新时间:2023-11-03 16:48:37 25 4
gpt4 key购买 nike

我正在尝试将字符串附加到传出的 Outlook.MailItem。在发送事件处理程序中,我有:

switch (mailItem.BodyFormat) {
case Outlook.OlBodyFormat.olFormatRichText:
byte[] mailItemBytes = mailItem.RTFBody as byte[];
System.Text.Encoding encoding = new System.Text.ASCIIEncoding();
string RTF = encoding.GetString(mailItemBytes);
RTF += "my string";
byte[] moreMailItemBytes = encoding.GetBytes(RTF);
mailItem.RTFBody = moreMailItemBytes;
break;
// ...
}

但是收到的邮件不包含我的字符串。

最佳答案

我知道这是旧的并且已经有绿色检查,但在搜索类似问题后,我找到了一个页面,该页面很好地回答了如何使用 Word.Document 对象模型在 Outlook 项目中修改 RTF 正文。 https://www.add-in-express.com/forum/read.php?FID=5&TID=12738

基本上,您将文本视为 word 文档,而忘记了与 RTF 一起工作。您需要先将 Microsoft.Office.Interop.Word 的引用添加到您的项目中。

然后将using添加到你的项目中

using Word = Microsoft.Office.Interop.Word;

然后添加你的代码

Word.Document doc = Inspector.WordEditor as Word.Document;

//text body
string text = doc.Content.Text;

//end of file
int endOfFile = (text.Length) > 0 ? text.Length - 1 : 0;

//Select the point to add or modify text
Word.Range myRange = doc.Range(endOfFile, endOfFile);

//add your text to end of file
myRange.InsertAfter("my string");

关于c# - 使用 C# 编辑 Outlook.MailItem 的 RTFBody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4964121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com