简体   繁体   English

Outlook 2010 - 插入文本

[英]Outlook 2010 - Insert text

In Outlook 2010 using C#. 在使用C#的Outlook 2010中。

From a ribbon button, how do I add text to the top of an email body? 从功能区按钮,如何将文本添加到电子邮件正文的顶部?

This is what my goal is: User clicks on New e-Mail, then clicks on a custom ribbon button and the button adds text to the top of the body field 这就是我的目标:用户点击新电子邮件,然后点击自定义功能区按钮,该按钮将文本添加到正文字段的顶部

click another button and that same text is removed 单击另一个按钮,删除相同的文本

Kind of like a mood stamp 有点像心情邮票

Can someone point me in the direction of how to do this? 有人能指出我如何做到这一点的方向?

Here's a quick outline: 这是一个快速概述:

  • Subscribe to the click event of your ribbon button. 订阅功能区按钮的单击事件。
  • Get the Application.ActiveInspector() 获取Application.ActiveInspector()
  • Get its Inspector.CurrentItem 获取其Inspector.CurrentItem
  • Attempt to cast it to MailItem 尝试将其MailItemMailItem
    • If the cast fails, assume that it is some other Outlook item type (eg contact) and that you shouldn't do anything with it 如果强制转换失败,则假设它是某些其他Outlook项目类型(例如联系人),并且您不应该对其执行任何操作
  • Read the mail item's BodyFormat 阅读邮件项目的BodyFormat
  • Depending on the format, you will need to alter Body , RTFBody , or HTMLBody 根据格式,您需要更改BodyRTFBodyHTMLBody
    • The first one, representing the plain-text body, is trivial; 第一个代表纯文本的身体是微不足道的; you just prepend your text to it: 你只需将文字添加到它:
      mailItem.Body = "My text\\r\\n" + mailItem.Body;
    • The other two will require you to take care of formatting syntax 另外两个将要求您处理格式化语法

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

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