我开发了一个Outlook外接程序,使用带有C#的VSTO。
步骤1:我创建了一个用于约会探索的功能区,当单击功能区按钮时,读取.rtf
文件并将.rtf
文件插入约会主体。
try
{
Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
Outlook.AppointmentItem meetingItem = insp.CurrentItem() as Outlook.AppointmentItem;
if(meetingItem == null){
MessageBox.Show("the meeting is null,create a meeting Item");
meetingItem = (Outlook.AppointmentItem)insp.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
}
if(meetingItem != null) {
meetingItem.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
object missing = System.Reflection.Missing.Value;
Word.Application wordAppl;
Word.Document wordDoc;
Word.Selection wordSel = null;
wordDoc = (Word.Document)insp.WordEditor;
wordAppl = wordDoc.Parent as Word.Application;
wordDoc.Activate();
String path = "D://WordSendTest//template//en_US.rtf";
String fileName = path.ToString();
wordSel = (Word.Selection)wordAppl.Selection;
wordSel.Range.Delete(ref missing, ref missing);
object falseRef = false;
wordSel.Range.InsertFile(fileName, ref missing, ref falseRef, ref falseRef, ref falseRef);
}
}
catch (Exception ex)
{
MessageBox.Show("Robbin click error!"+ ex.ToString());
}
第2步:当用户点击“发送按钮”时,捕获ItemSend事件。
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
第3步:在电子邮件正文的末尾插入一些“字符串文本”。
void Application_ItemSend(object Item, ref bool Cancel)
{
Outlook.Inspector insp = Globals.ThisAddIn.Application.ActiveInspector();
Outlook.AppointmentItem meeting = insp.CurrentItem as Outlook.AppointmentItem;
Word.Document wordDoc = insp.WordEditor as Word.Document;
Word.Application wordApp = wordDoc.Parent as Word.Application;
Word.Selection wordSel =(Word.Selection) wordApp.Selection;
object missing = System.Reflection.Missing.Value;
object units = Microsoft.Office.Interop.Word.WdUnits.wdStory;
object findEnd = (object)"~-----~~-----~-----~-----~-----~-----~\r";
object wholeWord = true;
wordSel.HomeKey(ref units, ref missing);
if(wordSel.Find.Execute(ref findEnd,ref missing,ref wholeWord,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing))
{
wordSel.MoveUp(ref missing,ref missing,ref missing);
wordSel.TypeText("--=Head for Insert info =--\n");
wordSel.TypeText("when user click the <send button>,the Tex info will be insert and show here \n");
wordSel.TypeText("--=End for Insert info=--\n");
}
else {
MessageBox.Show("not fonud the END tag");
}
}
问题: 在调试模型中,单击“发送”按钮时,添加“文本”将成功插入到主体中。 但是,实际发出的邮件不会更改,只有在单击“发送按钮”之前才会更改。 当我在日历中打开约会时,正文正常,文本被成功插入到邮件正文的末尾。
那么,谁知道为什么?为什么邮件不会与更新正文一起发送,但更新邮件正文保存在日历中。
答案 0 :(得分:0)
修改文本的代码是什么?什么时候执行? 请记住,约会永远不会发送。单击“发送”时,Outlook会创建一个MeetingRequest obejct并将其发送。您可以修改该对象的唯一时间是处理Application.ItemSend事件。