Outlook appointments item——如何在“发送”时向RTF邮件正文中添加一些数据?点击
本文关键字:添加 正文 点击 数据 时向 item appointments Outlook 发送 RTF | 更新日期: 2023-09-27 18:16:46
我用VSTO和c#开发了一个outlook插件。
步骤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");
}
}
问题:在调试模型中,单击发送按钮时,添加文本将成功插入正文。但是,实际发出的邮件并没有改变,只是在点击"发送按钮"之前保持不变。当我在日历中打开约会时,正文正常,文本成功插入到邮件正文的末尾。
所以,谁知道为什么?为什么邮件没有随更新正文一起发出,而更新邮件正文保存在日历中
修改文本的代码是什么?什么时候执行?请记住,预约永远不会发送。当您单击Send时,Outlook将创建一个MeetingRequest对象并发送它。唯一可以修改该对象的时间是在处理应用程序时。ItemSend事件。