使用VSTO创建修改和删除outlook会议加载项(二)

使用VSTO创建修改和删除outlook会议加载项

 

获取组织者的电子邮件地址类似xxx@163.com:

var organizer = appointment.GetOrganizer();
string organizerAddress = GetEmailAddress(organizer.PropertyAccessor);
ConfigManager.PRSMTPAddress = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
public static string GetEmailAddress(PropertyAccessor pa)
{
    string PR_SMTP_ADDRESS = ConfigManager.PRSMTPAddress;
    string emailAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
    return emailAddress;
}

 

修改会议并发送,包括组织者或参会者转发会议:

public bool EditTencentMeeting(_MeetingItem meetingItem,AppointmentItem appointment)
{
    string sendEmailAddress = meetingItem.SendUsingAccount.SmtpAddress;            
    string organizerEmail = ScheduleMeeting.GetEmailAddress(appointment.GetOrganizer().PropertyAccessor);
    EditMeetingRequestModel requestModel = GetRequestModel(appointment);
    requestModel.OrganizerEmail = organizerEmail;
    if (sendEmailAddress.ToLower() == organizerEmail.ToLower())
    {
        //说明是组织者更新
        List<Invitees> listInvitees = GetInvitees(appointment.Recipients);
        requestModel.Recipients = listInvitees;
        requestModel.IsOrganizer = 1;
        return EditTencentMeeting(requestModel);
    }
    else
    {
        //说明是参会人更新
        //取出参会人本次邀请的参会人
        List<Invitees> listInvitees = GetInvitees(meetingItem.Recipients);
        requestModel.Recipients = listInvitees;
        requestModel.IsOrganizer = 0;
        return EditTencentMeeting(requestModel);
    }
}

 

获取参会人:

private List<Invitees> GetInvitees(Recipients recipients)
{
    List<Invitees> listInvitees = new List<Invitees>();
    foreach (var p in recipients)
    {
        if (p is Recipient recipient)
        {
            Invitees invitee = new Invitees();
            invitee.Email = ScheduleMeeting.GetEmailAddress(recipient.PropertyAccessor);
            var checkUser = listInvitees.Where(x => x.Email.ToLower() == invitee.Email.ToLower());
            if (checkUser != null && checkUser.Any())
            {
                continue;
            }
            invitee.Mode = EmailMode.User;
            if (recipient.DisplayType == OlDisplayType.olOrganization)
            {
                invitee.Mode = EmailMode.Org;
            }
            listInvitees.Add(invitee);
        }
    }
    return listInvitees;
}

 

需要注意的是:如果是参会人张三转发的会议,此处的参会人列表只包含张三收到会议时的参会人,组织者和参会人(包括张三本次转发邀请的参会人)后来邀请的参会人都不在该列表中,但是组织者转发会议则会包含所有的参会人。

 

posted @ 2022-10-12 19:10  microsoft_xin  阅读(81)  评论(0编辑  收藏  举报