我正在使用Outlook加载项来处理电子邮件附件,方法是将它们放在服务器上,并将电子邮件地址放入电子邮件中。如何在发送之前更新Outlook邮件正文文本
一个问题是,将URL添加到电子邮件正文的末尾后,用户的光标被重置为电子邮件的开头。
一个相关的问题是,我不知道光标在文本中的位置,所以我无法将我的URL插入到正确的位置。
下面是一些代码,显示我在做什么,为了简单起见,代码假定主体是纯文本。
private void MyAddIn_Startup(object sender, System.EventArgs e)
{
Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad);
}
void Application_ItemLoad(object Item)
{
currentMailItem = Item as Outlook.MailItem;
((Outlook.ItemEvents_10_Event)currentMailItem).BeforeAttachmentAdd += new Outlook.ItemEvents_10_BeforeAttachmentAddEventHandler(ItemEvents_BeforeAttachmentAdd);
}
void ItemEvents_BeforeAttachmentAdd(Outlook.Attachment attachment, ref bool Cancel)
{
string url = "A URL";
if (currentMailItem.BodyFormat == Outlook.OlBodyFormat.olFormatHTML)
{
// code removed for clarity
}
else if (currentMailItem.BodyFormat == Outlook.OlBodyFormat.olFormatRichText)
{
// code removed for clarity
}
else
currentMailItem.Body += attachment.DisplayName + "<" + url + ">";
Cancel = true;
}
http://stackoverflow.com/questions/38433898/c-sharp-outlook-how-can-i-get-the-cursor-position-在主题领域的一个马 – stuartd