- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我使用 UTF8Encoding 从 MailItem 对 RTFbody 进行了一些成功的编码。我能够撰写一封新电子邮件,执行所有新电子邮件操作,然后单击发送。点击发送后,我在电子邮件中附加了一个标签,该标签也被添加到类别中。这一切都通过 RTFBbody 起作用。
当我回复 RTF 电子邮件时出现问题,出于测试目的,这些电子邮件只是我发送给孤独的自己的电子邮件。当我发送回复电子邮件并添加新标签时,我先删除旧标签,然后添加新标签。当我在回复电子邮件中使用包含新标签的已编辑字符串设置 RTFBody
时,我收到“内存或磁盘空间不足”错误。当我只是删除具有相同功能的标签时,不会发生这种情况。
下面是我使用的代码:
private void ChangeRTFBody(string replaceThis, string replaceWith)
{
byte[] rtfBytes = Globals.ThisAddIn.email.RTFBody as byte[];
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
string rtfString = encoding.GetString(rtfBytes);
rtfString = rtfString.Replace(replaceThis, replaceWith);
rtfBytes = encoding.GetBytes(rtfString);
Globals.ThisAddIn.email.RTFBody = rtfBytes; < // The error is here only on
// reply and only when I replace
// with new tags
}
这些是我打的电话:
删除旧标签:ChangeRTFBody(lastTag, "");
添加新标签:ChangeRTFBody("}}\0", newTag + "}}\0");
就像我说的,这在我创建并发送新电子邮件时有效,但在我尝试回复同一封电子邮件时无效。似乎 byte[]
的大小在删除后几乎翻了一番。当我在删除期间检查它时,它大约有 15k 字节,而当我在添加期间检查它时,它跳到超过 30k 字节。当我尝试将新膨胀的 byte[]
添加到 rtfBody 时,我得到了错误。
感谢您提供的任何帮助和提示,对所有阅读感到抱歉。
最佳答案
我遇到了同样的问题,并且遇到了我认为使用 Word.Document 对象模型替换 outlook rtf 正文中的文本的更简单方法。您需要先将 Microsoft.Office.Interop.Word 的引用添加到您的项目中。
然后添加使用
using Word = Microsoft.Office.Interop.Word;
那么你的代码看起来像
Word.Document doc = Inspector.WordEditor as Word.Document;
//body text
string text = doc.Content.Text;
//find text location
int textLocation = text.IndexOf(replaceThis);
if(textLocation > -1){
//get range
int textLocationEnd = textLocation + replaceThis.Length;
//init range
Word.Range myRange = doc.Range(textLocation , textLocationEnd);
//replace text
myRange.Text = replaceWith
}
关于c# - 通过编码编辑 MailItem.RTFBody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15232737/
关闭。这个问题需要debugging details .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve this questio
我正在开发一个 MFC 应用程序,它捕获一些 Outlook 事件,包括 Application.Send 和 Items.ItemAdd 事件。发送电子邮件时,我会保存它以获取其大小(如果不这样做,
我正在尝试了解如何在 Outlook 2007 中通过 VBA 将 MailItem 的后续标志设置为完成? Google 搜索返回了大量在 Outlook 2003 及之前版本中有效的方法(例如,更
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: java non-static method getBalance cannot be referenced fro
背景: 目前我正在搜索属于 advancedSearch() 查询结果集的 MailItems。 link to the doc Outlook.Search advancedSearch = App
我在 Outlook Explorer 中添加了一个功能区按钮,单击它会从选定的电子邮件中创建一封新电子邮件。使用 MailItem.Copy 方法效果很好。但我还需要用不同的值替换消息正文中的一些文
是否可以直接将 MailItem 作为 Stream 返回?(MailItem 来自 Microsoft.Office.Interop.Outlook) 现在我找到了一个临时解决方案,首先将一个 Ma
我正在 Outlook 中实现带有电子邮件消息的自定义任务 Pane 。核心取自此链接 MSDN (Walkthrough: Displaying Custom Task Panes with E-M
当我传递 olMHTML 时,它以 .msg 扩展名保存它,但如果我将扩展名更改为 .mht,它就可以完美地用作 mht 文件,如果我不这样做,我将无法打开扩展名为 .msg 的文件。如果我将它保存为
我使用 UTF8Encoding 从 MailItem 对 RTFbody 进行了一些成功的编码。我能够撰写一封新电子邮件,执行所有新电子邮件操作,然后单击发送。点击发送后,我在电子邮件中附加了一个标
我正在尝试从我的加载项中捕获 MailItem 对象。我试着查看 Globals.FormRegions 但没有找到任何结果。知道如何在新的撰写窗口中访问 Outlook.MailItem 吗? 最佳
有什么方法可以确定 MailItem 是在 ReadMail View (不确定这里的术语)还是在 Compose 中打开查看。也就是说,我是在打开一封已发送给我的邮件,还是在打开一封要发送给某人的邮
下面的代码不会收到我在收件箱中的所有电子邮件。 我列表框中的第一项是昨天和 2014 年 4 月 22 日最后一封电子邮件——尽管我的邮箱包含的远不止这些。 Sub CheckEmail() On E
有没有办法以异步方式将 Outlook.MailItem 保存为 .msg 文件? 我正在使用: MailItem.SaveAs("path", Outlook.OlSaveAsType.olMSG)
我正在为 Outlook 2007 和 2010 开发一个 C# 插件。 假设我有当前显示邮件的 Outlook.MailItem 对象,我想用按钮替换部分邮件文本,这将调用内部加载项函数(传递一些当
我正在使用 C# 开发 OUTLOOK 2010 插件。此插件将根据对话创建事件。例如,一个用户创建新电子邮件,其他用户回复、转发或抄送,将此电子邮件链视为一个 session 线程。这些电子邮件具有
我正在为 Outlook 2007 开发一个 outlook 插件。简而言之:我需要在用户打开电子邮件时获取电子邮件发件人的事件目录用户主体对象。 我想要实现的目标: 获取此电子邮件的发件人 获取此发
我们正在开发 outlook 插件。我们提供一个按钮作为默认发送按钮的替代方案。我们需要将按钮回复的所有 MailItem 保存到特定类别。当用户回复电子邮件时(在新的检查器中),我怎样才能让主要的
如何在 Outlook.MailItem 上设置随后不与收件人共享的属性? 示例代码: Outlook.UserProperties mailUserProperties = null; Outloo
我正在尝试编写一个加载项,它可以在加载时修改 Outlook MailItem(通过预览 Pane 或通过它打开)。这是我到目前为止的代码,但我似乎无法实际访问 MailItem public par
我是一名优秀的程序员,十分优秀!