发送带有赎回的邮件/任务/约会

问题描述 投票:0回答:1

我正在尝试以编程方式向用户发送邮件/任务/约会,但我遇到了问题,每次我向他们发送邮件时,第一个邮件都会卡在我的发件箱中……似乎第一个发送到Outlook的邮件没有/丢失其发送日期,并将永远留在我的发件箱中。

这里是例如“发送任务通知”的代码

using (MapiSession session = new MapiSession())
{
    var item = session.CreateItem(Outlook.OlItemType.olTaskItem) as RDOTaskItem;
    [..]
    try
    {
        item.Subject = "SUBJECT";
        item.Body = "BODY;

        item.StartDate = DateTime.Now;
        item.DueDate = DateTime.Now;

        item.Recipients.Add("[email protected]");
        item.Recipients.Add("[email protected]");

        item.Recipients.ResolveAll();
        item.Assign();
        item.Save();
        item.Send();
    }
    [..]
}

提前感谢。

outlook notifications mapi outlook-redemption
1个回答
0
投票

所以我现在还不能真正解决问题所在...如果所有接收者都是其他人,那么我自己应该可以工作...

这是我的代码,用于发送TaskItem

private void NotifyByTask(OutlookNotificationTypes notificationType)
{
    Application app = new Application();
    var item = app.CreateItem(OlItemType.olTaskItem) as TaskItem;

    try
    {
        item.Subject = this.Subject;
        item.Body = this.Body;

        if (this.Start != DateTime.MinValue)
        {
            item.StartDate = this.Start;
            item.ReminderSet = true;
            item.ReminderPlaySound = true;
            item.ReminderTime = this.Start.AddMinutes(-5);
        }
        if (this.End != DateTime.MinValue)
        {
            item.DueDate = this.End;
        }
        item.PercentComplete = this.PercentComplete;

        StringBuilder categories = new StringBuilder();
        foreach (String category in this.Categories)
        {
            categories.Append(category);
        }
        item.Categories = categories.ToString();

        bool sendingToMyself = false;
        if (this.NotificationType == OutlookNotificationTypes.TaskRequest)
        {
            // this will add all recipients and checks if Receiver is yourself
            sendingToMyself = item.AddRecipients(this.Recipients, OlMailRecipientType.olTo);
        }
        if (this.NotificationType == OutlookNotificationTypes.TaskRequest 
            && (!sendingToMyself))
        {
            item.Recipients.ResolveAll();
            item.Assign();
            item.Save();
            item.Send();
        }
        else
        {
            item.Save();

            //insert element
            if (this.ItemSaved != null)
            {
                Microsoft.Office.Interop.Outlook.MAPIFolder folder =
                                item.Parent as Microsoft.Office.Interop.Outlook.MAPIFolder;

            if (folder != null)
            {    
                try
                {
                    String storeId = folder.StoreID;
                    String entryId = item.EntryID;
                    this.ItemSaved(storeId, entryId);
                }
                finally
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(folder);
                }
            }
        }
    }
}
finally
{
    System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
}
}
© www.soinside.com 2019 - 2024. All rights reserved.