Отправить почту / задачу / встречу с выкупом - PullRequest
0 голосов
/ 18 февраля 2020

Я пытаюсь программно отправить пользователю письмо / задачу / встречу, и у меня проблема в том, что каждый раз, когда я отправляю их, первая из них застревает в моем почтовом ящике ... Кажется, что первая отправлена ​​на 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("test@mail.com");
        item.Recipients.Add("test2@mail.com");

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

Заранее спасибо.

1 Ответ

0 голосов
/ 20 февраля 2020

Так что я не совсем уверен, в чем проблема ... Пока все получатели являются другими лицами, тогда я сам должен работать ...

Вот мой код для отправки 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);
}
}
...