Я работаю над надстройкой Outlook для обработки вложений электронной почты, размещая их на сервере и помещая вместо него URL-адрес в электронном письме.Как обновить внешний текст почты 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- in-the-subject-field-of-a-ma – stuartd