c# - VSTO: How to trigger the Check Names action in Active Mail item -
i'm creating microsoft office 2013 add-in behaviour similar address book in active mail item:
i'm working microsoft.office.interop.outlook.mailitem , using recipients property, , recipients.resolveall() method load , remove addresses it, seems work fine until click ok on loaded send control active mail item. @ point outlook goes crazy , doesn't place addresses in or cc, or of them go missing.
i'm thinking 1 solution problem trigger check names when user ready click ok , send addresses form active mail item.
how can trigger action / button?
i couldn't find in mailitem class. similar (but use within poped-out windows form in outloook):
update:
this bits of code add more context:
i use method addrecipienttoactiveitem each item have. verify if exists (it added), if not resolve , if correct add it.
private void addrecipienttoactiveitem(string recipientaddress, recipients recipientlist, olmailrecipienttype recipienttype) { recipient recipientobject = default(recipient); if (!string.isnullorwhitespace(recipientaddress) && !emailrecipientalreadyexists(recipientaddress, recipienttype)) { recipientobject = recipientlist.add(recipientaddress); recipientobject.resolve(); if (recipientobject.resolved) { recipientobject.type = (int)recipienttype; recipientlist.resolveall(); } else { recipientobject.delete(); } } }
for this, have iterate through each element in list of recipients , compare address + type (from,to,cc,bcc) pair:
private bool emailrecipientalreadyexists(string fullemailaddress, olmailrecipienttype recipienttype) { foreach (microsoft.office.interop.outlook.recipient recipientobject in activemailitem.recipients) { if (getrecipientemailaddress(recipientobject) != null) { if (getrecipientemailaddress(recipientobject).equals(fullemailaddress) && recipientobject.type == (int)recipienttype) return true; } } return false; }
but user can add addresses email item manually, , of them exist in exchange server, others simple smtp address, when comparing have handle both scenarios:
private string getrecipientemailaddress(microsoft.office.interop.outlook.recipient recipientobject) { outlook.exchangeuser objexchangeuser = null; if (recipientobject.address != null && recipientobject.addressentry != null) objexchangeuser = recipientobject.addressentry.getexchangeuser(); if (recipientobject.address == null && objexchangeuser == null) return recipientobject.name; if (objexchangeuser == null) return recipientobject.address; return objexchangeuser.primarysmtpaddress; } }
it seems i've done not enough keep consistent states of email addresses when read them mail item , put them in text box of form, add more addresses , send them mail item , close form, , repeat process.
the namespace class provides getselectnamesdialog method obtains selectnamesdialog object current session. displays select names dialog box user select entries 1 or more address lists, , returns selected entries in collection object specified property selectnamesdialog.recipients.
sub selectrecipients() dim omsg mailitem set omsg = application.createitem(olmailitem) dim odialog selectnamesdialog set odialog = application.session.getselectnamesdialog odialog .initialaddresslist = _ application.session.getglobaladdresslist .recipients = omsg.recipients if .display 'recipients resolved omsg.subject = "hello" omsg.send end if end end sub
the dialog box displayed selectnamesdialog.display similar select names dialog box in outlook user interface. observes size , position settings of built-in select names dialog box. however, default state not show message recipients above to, cc, , bcc edit boxes. more information on using selectnamesdialog object display select names dialog box, see display names address book.
Comments
Post a Comment