Email Outlook加载项抛出我不知道的错误';我不明白

Email Outlook加载项抛出我不知道的错误';我不明白,email,outlook,Email,Outlook,我正在尝试编写一个outlook加载项,它可以从用户的收件箱中读取约会,并在会议前72小时生成提醒电子邮件。我通过拼凑来自SO和web的代码片段学会了如何做到这一点,但我遇到了一些错误。我不确定我是否了解发生了什么,甚至不能提出正确的问题,所以请原谅我在这件事上的笨拙 因此,当我尝试使用下面的代码欺骗“发件人”时,我得到以下错误: "Generating server: MBX080-W3-CO-1.exch080.serverpod.net josh.alcorn@crmpoint.net R

我正在尝试编写一个outlook加载项,它可以从用户的收件箱中读取约会,并在会议前72小时生成提醒电子邮件。我通过拼凑来自SO和web的代码片段学会了如何做到这一点,但我遇到了一些错误。我不确定我是否了解发生了什么,甚至不能提出正确的问题,所以请原谅我在这件事上的笨拙

因此,当我尝试使用下面的代码欺骗“发件人”时,我得到以下错误:

"Generating server: MBX080-W3-CO-1.exch080.serverpod.net
josh.alcorn@crmpoint.net
Remote Server returned '550 5.6.2 STOREDRV.Submit; subscription not found'
Original message headers:
Received: from MBX080-W3-CO-1.exch080.serverpod.net ([10.224.117.52]) by
 MBX080-W3-CO-1.exch080.serverpod.net ([169.254.1.30]) with mapi id
 15.00.1044.021; Mon, 8 Jun 2015 08:28:25 -0700
MIME-Version: 1.0
Content-Type: text/plain
Date: Mon, 8 Jun 2015 08:28:25 -0700
X-MS-Exchange-Transport-FromEntityHeader: Hosted
Message-ID:
    <b8690284ffb04af794a676b8efdee58d@MBX080-W3-CO-1.exch080.serverpod.net>
Subject: This is the subject"
“生成服务器:MBX080-W3-CO-1.exch080.serverpod.net
乔希。alcorn@crmpoint.net
远程服务器返回“550 5.6.2 STOREDRV.Submit;未找到订阅”
原始邮件标题:
收到:从MBX080-W3-CO-1.exch080.serverpod.net([10.224.117.52])收到
带有mapi id的MBX080-W3-CO-1.exch080.serverpod.net([169.254.1.30])
2015年6月8日星期一08:28:25-0700
MIME版本:1.0
内容类型:文本/纯文本
日期:2015年6月8日星期一08:28:25-0700
X-MS-Exchange-Transport-FromEntityHeader:托管
消息ID:
主题:这是主题“
当我删除发送方代码时,它似乎为我的两个测试约会正确触发,但在第三个测试约会上抛出nullreferenceexception。我似乎不知道如何将调试器与Outlook结合使用,因此我没有关于该错误的更多信息。对于这个问题,任何关于如何实时调试Outlook 2013插件的建议都将不胜感激。我已经尝试了所有我知道的技巧

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;

//http://stackoverflow.com/questions/6425776/outlook-2010-how-to-get-a-list-of-all-appointments-including-recurrences
//https://www.add-in-express.com/creating-addins-blog/2013/06/10/outlook-calendar-appointment-meeting-items/
//http://www.sperrysoftware.com/outlook/email-reminders.asp
//myEmailAddress = this.ActiveExplorer().Session.CurrentUser.EmailAddress;
//Application.Session.CurrentUser.AddressEntry.Address
//https://www.add-in-express.com/creating-addins-blog/2013/06/10/outlook-calendar-appointment-meeting-items/#enumerate
//http://www.scrubly.com/blog/how-to-outlook/how-to-install-enable-and-disable-outlook-2013-add-ins/
//http://stackoverflow.com/questions/5472493/making-vsto-add-in-installable
//https://msdn.microsoft.com/en-us/library/cc442767.aspx#Download

namespace OutlookAddIn1
{
    public partial class ThisAddIn
    {
        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()
    {
        Thread.Sleep(120000); //120 seconds

        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.olFolderCalenda    r);
                    Outlook.Items outlookCalendarItems =        calendarFolder.Items;
                    outlookCalendarItems.IncludeRecurrences = false; //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)
                    {
                        //http://stackoverflow.com/questions/16329581/getting-system-runtime-interopservices-comexception-error-in-server-side-generat
                        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)
                            {
                                Outlook.MailItem mailItem = (Outlook.MailItem)
                                    this.Application.CreateItem(Outlook.OlItemType.olMailItem);
                                //http://stackoverflow.com/questions/11223462/how-to-send-a-mail-using-microsoft-office-interop-outlook-mailitem-by-specifying
                                //Outlook.Recipient recipient = this.Application.Session.CreateRecipient("someone@example.com");
                                //mailItem.Sender = recipient.AddressEntry;
                                Outlook.Recipient recipTo =
                                    mailItem.Recipients.Add("someone@example.com");
                                recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
                                mailItem.Sender = (Outlook.AddressEntry)recipTo;
                                //Outlook.Account account = new Account();// Application.Session.Accounts["MyOtherAccount"];

                                //mailItem.SendUsingAccount = account;

                                mailItem.Subject = "This is the subject";
                                mailItem.To = Application.Session.CurrentUser.AddressEntry.Address; //"someone@example.com";
                                mailItem.Body = "This is the message.";
                                mailItem.Importance = Outlook.OlImportance.olImportanceLow;
                                mailItem.Display(false);
                                ((Outlook._MailItem)mailItem).Send();
                                //mailItem.Send();
                                /*
                                //Here we generate the email
                                Outlook.Application app = new Outlook.Application();
                                Microsoft.Office.Interop.Outlook.MailItem email = app.CreateItem((OlItemType.olMailItem));

                                Outlook.Recipient recipient = app.Session.CreateRecipient("someone@example.com");
                                email.Sender = recipient.AddressEntry;
                                email.Display(false);
                                email.Subject = "You have a new appointment";
                                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();
                                ((Outlook._MailItem)email).Send();
                                //email.Send();
                                //((Outlook._MailItem)mailItem).Send();
                                app.Quit();
                                 * */
                            }
                        }
                    }

                    lastRun = DateTime.Now;
                    whileTrue = false;
                }
                else
                {
                }
            }
        }
        catch (System.Exception e) //Microsoft.Office.Interop.Outlook.Exception e
        {
            MessageBox.Show(e.ToString());
        }



    }

    public void createContact()
    {
        Outlook.ContactItem newContact = (Outlook.ContactItem)
            this.Application.CreateItem(Outlook.OlItemType.olContactItem);
        try
        {
            newContact.FirstName = "Person";
            newContact.LastName = "LastName";
            newContact.Email1Address = "someone@example.com";
            newContact.Save();
            newContact.Display(true);
        }
        catch
        {
            MessageBox.Show("The new contact was not saved.");
        }
    }


    #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;
//http://stackoverflow.com/questions/6425776/outlook-2010-how-to-get-a-list-of-all-appointments-including-recurrences
//https://www.add-in-express.com/creating-addins-blog/2013/06/10/outlook-calendar-appointment-meeting-items/
//http://www.sperrysoftware.com/outlook/email-reminders.asp
//myEmailAddress=this.ActiveExplorer().Session.CurrentUser.EmailAddress;
//Application.Session.CurrentUser.AddressEntry.Address
//https://www.add-in-express.com/creating-addins-blog/2013/06/10/outlook-calendar-appointment-meeting-items/#enumerate
//http://www.scrubly.com/blog/how-to-outlook/how-to-install-enable-and-disable-outlook-2013-add-ins/
//http://stackoverflow.com/questions/5472493/making-vsto-add-in-installable
//https://msdn.microsoft.com/en-us/library/cc442767.aspx#Download
命名空间了望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
私人无效文件()
{
Thread.Sleep(120000);//120秒
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.MAPIFolder calendarFolder=Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items outlookCalendarItems=calendarFolder.Items;
outlookCalendarItems.IncludeCurrences=false;//为true
List lst=新列表();
foreach(Outlook日历项目中的Outlook.AppointmentItem项目)
{
一、增加(项目);
//我们可以在这里处理逻辑,而不需要接下来的第二个for循环
}
foreach(Outlook.AppointmentItem x在lst中)
{
//http://stackoverflow.com/questions/16329581/getting-system-runtime-interopservices-comexception-error-in-server-side-generat
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