Kvu
Kvu

Reputation: 309

Recipients become zero after updating HTMLBody of occurrence Outlook Redemption

UPDATE

Ultimate goal is to send the updated body to the existing recipients of the meeting occurrence.

I'm trying to update HTMLBody of occurrence of existing meeting with number of recipients.

After updated the HTMLBody, recipients count is become zero.

And sending failed with an error saying "message contains no recipients"

Here's the code I've tried.

public static void GetSomething()
{
    var entryID = "00000000C97FEB5BB4BE2046B4C77ADEB3C423010700BA6ADFD7533DD244B122D7B9F3B5664000000000010D0000BA6ADFD7533DD244B122D7B9F3B56640000269310F930000";
    RDOAppointmentItem appointment = null;
    RDORecurrencePattern pattern = null;
    RDOMail occurrence = null;
    try
    {
        appointment = rSession.GetMessageFromID(entryID) as RDOAppointmentItem;
        if (appointment != null)
        {
            pattern = appointment.GetRecurrencePattern();
            if (pattern != null)
            {
                occurrence = pattern.GetOccurrence(1);
                if (pattern != null) Marshal.ReleaseComObject(pattern);
                if (appointment != null) Marshal.ReleaseComObject(appointment);
                occurrence.HTMLBody = @"<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<title>Page Title</title>\r\n</head>\r\n<body>\r\n<p>This is a paragraph.</p>\r\n\r\n</body>\r\n</html>";
                occurrence.Send();
            }
        }
    }
    catch (Exception e)
    {
        Debug.DebugMessage(2, $"Error in {MethodBase.GetCurrentMethod().Name} | {e.Message}");
    }
    finally
    {
        if (occurrence != null) Marshal.ReleaseComObject(occurrence);
    }
}

I then tried the approach of adding and removing a recipient which worked but added recipient is not removed from the meeting request sent, although it was removed from the appointment in my calendar.

Here's the code I've tried for that.

public static void GetSomething()
    {
        var entryID = "00000000C97FEB5BB4BE2046B4C77ADEB3C423010700BA6ADFD7533DD244B122D7B9F3B5664000000000010D0000BA6ADFD7533DD244B122D7B9F3B56640000269310F930000";
        RDOAppointmentItem appointment = null;
        RDORecurrencePattern pattern = null;
        RDOMail occurrence = null;
        try
        {
            appointment = rSession.GetMessageFromID(entryID) as RDOAppointmentItem;
            if (appointment != null)
            {
                pattern = appointment.GetRecurrencePattern();
                if (pattern != null)
                {
                    occurrence = pattern.GetOccurrence(1);
                    if (pattern != null) Marshal.ReleaseComObject(pattern);
                    if (appointment != null) Marshal.ReleaseComObject(appointment);
                    RDORecipients oldRecipients = occurrence.Recipients;
                    var oldRecCount = oldRecipients.Count;
                    RDORecipient recipient = oldRecipients.AddEx("Test", "[email protected]", "SMTP", 1);
                    if (recipient != null) Marshal.ReleaseComObject(recipient);
                    if (oldRecipients != null) Marshal.ReleaseComObject(oldRecipients);
                    occurrence.HTMLBody = @"<!DOCTYPE html>\r\n<html>\r\n<head>\r\n<title>Page Title</title>\r\n</head>\r\n<body>\r\n<p>This is a paragraph.</p>\r\n\r\n</body>\r\n</html>";
                    RDORecipients newRecipients = occurrence.Recipients;
                    newRecipients.Remove(oldRecCount + 1);
                    if (newRecipients != null) Marshal.ReleaseComObject(newRecipients);
                    occurrence.Send();
                }
            }
        }
        catch (Exception e)
        {
            Debug.DebugMessage(2, $"Error in {MethodBase.GetCurrentMethod().Name} | {e.Message}");
        }
        finally
        {
            if (occurrence != null) Marshal.ReleaseComObject(occurrence);
        }
    }
}

 

Upvotes: 1

Views: 108

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66255

Keep in mind that occurrences do not physically exist - when you ask for an occurrence, Redemption creates a fake appointment object that gets most of its properties (except for the start/end and recurrence) from the master appointment.

When you create an exception (by modifying one of the properties), besides modifying the exception pattern, an appointment is created and added an an embedded message attachment to the master appointment. That appointment stores mostly modified properties. Since the recipients were not modified for the exception, the recipient table is empty.

Upvotes: 1

Related Questions