2个多月无法使用outlook加载项
这基本上是前一个问题的重发,但我花了两个多月的时间在同一个问题上,没有取得任何进展。长话短说,有时会起火,有时不会。有时它只加载一次,有时Outlook将其默认为“非活动”,对此我似乎无能为力。当它启动时,它会在尝试发送第一封电子邮件时挂断。因此,我有我正在检查的日期范围之外的旧约会,并且会显示这些约会的messagebox。当它到达“新”约会(在日期范围内)时,有时会弹出第一个消息框,但在尝试发送电子邮件时挂断。有时,第一个“好”消息框无法弹出。关于这个问题,我得到的最后一个建议是建立一个日志文件,但我不知道它对我有什么好处,或者说实话,我甚至不确定我需要记录什么,当我问起这个问题时,提出这个建议的那位先生从未回复过我。提前感谢您的帮助,这是我作为开发人员遇到的最令人沮丧的事情之一2个多月无法使用outlook加载项,outlook,add-in,Outlook,Add In,这基本上是前一个问题的重发,但我花了两个多月的时间在同一个问题上,没有取得任何进展。长话短说,有时会起火,有时不会。有时它只加载一次,有时Outlook将其默认为“非活动”,对此我似乎无能为力。当它启动时,它会在尝试发送第一封电子邮件时挂断。因此,我有我正在检查的日期范围之外的旧约会,并且会显示这些约会的messagebox。当它到达“新”约会(在日期范围内)时,有时会弹出第一个消息框,但在尝试发送电子邮件时挂断。有时,第一个“好”消息框无法弹出。关于这个问题,我得到的最后一个建议是建立一个日志
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
//Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
doStuff();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
//https://msdn.microsoft.com/en-us/library/ms268866.aspx
private void doStuff()
{
Outlook.Application app = new Outlook.Application();
Thread.Sleep(30000); //120 seconds - was 120000
DateTime firstRun = DateTime.Now; //So we can check every 24 hours? Maybe once initially as well.
DateTime lastRun = DateTime.Now;//.AddHours(1); //We're going to compare this to firstRun
bool whileTrue = true;
//int test = 0;
try
{
while (whileTrue)
{
if (whileTrue == true)//(firstRun > lastRun.AddDays(1))
{
Outlook.MAPIFolder calendarFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items outlookCalendarItems = calendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true; //was true
List<Outlook.AppointmentItem> lst = new List<Outlook.AppointmentItem>();
foreach (Outlook.AppointmentItem item in outlookCalendarItems)
{
lst.Add(item);
//We can probably just handle logic in here without the second for loop that comes next
}
foreach (Outlook.AppointmentItem x in lst)
{
DateTime startDate = DateTime.Now.AddDays(1);
DateTime endDate = DateTime.Now.AddDays(5);
DateTime apptDate = x.Start;
if (x.Subject.ToLower().Contains("telos"))
{
MessageBox.Show("X: " + x.Start + "XYZ: " + x.Subject);
if (x.Start > startDate && x.Start < endDate)
{
Microsoft.Office.Interop.Outlook.MailItem email = app.CreateItem((OlItemType.olMailItem));
//Outlook.MailItem mail = (Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
//Outlook.Recipient recipient = Globals.ThisAddIn.Application.Session.CreateRecipient("cindy@soundstewardship.com");
//email.Sender = recipient.AddressEntry;
//Outlook.Recipient recipient = app.Session.CreateRecipient("someone@example.com");
//email.Sender = recipient.AddressEntry;
//email.SentOnBehalfOfName = "someone@example.com";
email.Display(true); //was false
email.Subject = "You have a new appointment";
email.Importance = Outlook.OlImportance.olImportanceLow;
email.To = Application.Session.CurrentUser.AddressEntry.Address; //Current email address.
email.Body = "This email was automatically generated to remind you have an upcoming appointment on: " + x.Start.ToString();
email.Save();
email.Close(OlInspectorClose.olSave);
//((Outlook._MailItem)email).Send();
//email.Send();
//((Outlook._MailItem)mailItem).Send();
}
}
}
lastRun = DateTime.Now;
whileTrue = false;
}
else
{
/*
Outlook.MailItem email = new Outlook.MailItem();
email.Subject = "This is only a test.";
email.To = Application.Session.CurrentUser.AddressEntry.Address; //Current email address.
email.Body = "This is only a test.";
//email.Send();
((Outlook._MailItem)email).Send();
* */
}
}
}
catch (System.Exception e) //Microsoft.Office.Interop.Outlook.Exception e
{
MessageBox.Show(e.InnerException.ToString());
}
finally
{
app.Quit();
}
}
#endregion
}
使用系统;
使用系统线程;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml.Linq;
使用Outlook=Microsoft.Office.Interop.Outlook;
使用Office=Microsoft.Office.Core;
使用Microsoft.Office.Interop.Outlook;
使用System.Windows.Forms;
命名空间了望AddIn1
{
公共部分类ThisAddIn
{
//展望.视察员;
私有void ThisAddIn_启动(对象发送方,System.EventArgs e)
{
doStuff();
}
私有void ThisAddIn_关闭(对象发送方,System.EventArgs e)
{
}
#区域VSTO生成的代码
///
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
///
私有void InternalStartup()
{
this.Startup+=new System.EventHandler(ThisAddIn\u启动);
this.Shutdown+=new System.EventHandler(ThisAddIn\u Shutdown);
}
//https://msdn.microsoft.com/en-us/library/ms268866.aspx
私人无效文件()
{
Outlook.Application app=新建Outlook.Application();
Thread.Sleep(30000);//120秒-是120000秒
DateTime firstRun=DateTime.Now;//所以我们可以每24小时检查一次?最初也可以检查一次。
DateTime lastRun=DateTime.Now;//.AddHours(1);//我们将把它与firstRun进行比较
bool whileTrue=真;
//int检验=0;
尝试
{
whileTrue(whileTrue)
{
如果(whileTrue==true)/(firstRun>lastRun.AddDays(1))
{
Outlook.MapipFolder calendarFolder=Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items outlookCalendarItems=calendarFolder.Items;
outlookCalendarItems.IncludeCurrences=true;//为true
List lst=新列表();
foreach(Outlook日历项目中的Outlook.AppointmentItem项目)
{
一、增加(项目);
//我们可以在这里处理逻辑,而不需要接下来的第二个for循环
}
foreach(Outlook.AppointmentItem x在lst中)
{
DateTime startDate=DateTime.Now.AddDays(1);
DateTime endDate=DateTime.Now.AddDays(5);
DateTime apptDate=x.开始;
如果(x.Subject.ToLower()包含(“telos”))
{
MessageBox.Show(“X:+X.Start+”XYZ:+X.Subject);
如果(x.Start>startDate&&x.Start