using System; using System.Collections.Generic; using System.Linq; using System.Text; using Outlook = Microsoft.Office.Interop.Outlook; namespace Outlook2013TodoAddIn { public class OutlookHelper { #region "Variables" /// /// Used to retrieve the email address of a contact /// private const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; #endregion "Variables" #region "Methods" /// /// Resolves Outlook recipient email address /// /// Recipient /// Email address of the contact public static string GetEmailAddress(Outlook.Recipient rcpt) { Outlook.PropertyAccessor pa = rcpt.PropertyAccessor; return pa.GetProperty(PR_SMTP_ADDRESS).ToString(); } /// /// Gets a list of recipients email addresses, and when exception is present will not be included /// /// Recipients /// Email address exception /// List of emails public static List GetRecipentsEmailAddresses(Outlook.Recipients rcpts, string exception) { List results = new List(); foreach (Outlook.Recipient rcpt in rcpts) { string smtpAddress = OutlookHelper.GetEmailAddress(rcpt); if (smtpAddress != exception && !results.Contains(smtpAddress)) { results.Add(smtpAddress); } } return results; } /// /// Rounds up a datetime to the nearest X interval /// e.g.: RoundUp(new DateTime(2013, 6, 18, 13, 43, 10), TimeSpan.FromMinutes(15)); -> 6/18/2013 1:45:00 PM /// /// DateTime /// TimeSpan /// public static DateTime RoundUp(DateTime dt, TimeSpan d) { return new DateTime(((dt.Ticks + d.Ticks - 1) / d.Ticks) * d.Ticks); } #endregion "Methods" } }