Udostępnij za pośrednictwem


Outlook Add-in: Replying to people who voted

Recently, I asked my colleagues if they were interested in beta testing some software I’m building for internal use. I used voting buttons to enable easy tracking of replies. When I wanted to reply to all people who voted “Yes” on my request, I discovered there’s no real way of just replying to a set of people who voted a certain way. Meet “ReplyToVoteTrackingType” (what’s in a name?); it’s an add-in which allows you to easily reply to anyone who casted a certain vote by selecting that vote:

 

The code for the add-in is pretty straight-forward, when loading the Ribbon we fill the dropdown menu with the items from the original vote and hookup the same event handler (we don’t discriminate) to each added button:

 // Retrieve the MailItem we're currently viewing.
currentItem = ((InspectorClass)this.Context).CurrentItem as MailItem;
// Retrieve all possible voting options from when we sent out the e-mail.
string[] votingOptions = currentItem.VotingOptions.Split(new char[] { ';' });

// Set up a button for each of the options, labeled <option> ('yes', 'no', etc.).
foreach (string votingOption in votingOptions)
{
    RibbonButton btn = new RibbonButton() { Label = votingOption, SuperTip = string.Format(Resources.SuperTip, votingOption) };
    btn.Click += clickEventHandler;
    mnuReplyToTracking.Items.Add(btn);
}

Then, when the end user clicks on any of the voting options (e.g. “Yes” as the picture above shows), we check who responded in this fashion and add them to a newly created e-mail:

 StringBuilder recipients = new StringBuilder();

// For each recipient,
foreach (Recipient recipient in currentItem.Recipients)
{
    // if they responded, and the response is what the users choose for a target audience,
    if (recipient.AutoResponse != null && string.Compare(recipient.AutoResponse, ((RibbonButton)sender).Label, true, CultureInfo.InvariantCulture) == 0)
    {
        // add the recipient to the addressee list.
        recipients.AppendFormat("{0};", recipient.Name);
    }
}

// Set up a new e-mail to the addressees.
MailItem mail = ((InspectorClass)this.Context).Application.CreateItem(OlItemType.olMailItem) as MailItem;
mail.To = recipients.ToString();
// Convenience: set the mail subject to be "RE: <subject of voting e-mail>".
mail.Subject = string.Format(Resources.ReplyToVoteEmail, currentItem.Subject);
// Display the e-mail, non-modal.
mail.Display(false);

That’s all; now, when the end users wants to reach his/her audience given a certain vote, it’s as easy as click the right voting reply!

Source code is attached, as is an installer. As always, NO WARRANTIES.

Source code
Installer