exchangewebservices - Email to group using EWS C# -
i'm using exchangewebservices c#.
i'm trying send email distributio list, i'm created group follow:
private void creategroup(exchangeservice service) { // create new contact group object. contactgroup mycontactgroup = new contactgroup(service); // give group name. mycontactgroup.displayname = "testcontactgroup"; // add members group. mycontactgroup.members.add(new groupmember("euser@mydomain.com")); mycontactgroup.members.add(new groupmember("euser1@mydomain.com")); mycontactgroup.members.add(new groupmember("euser2@mydomain.com")); // save group. mycontactgroup.save(); }
now i'm trying send email group, how can that?
i'm tried:
emailmessage email = new emailmessage(service); email.torecipients.add("testcontactgroup");//throw exception "at least 1 recipient isn't valid." //email.torecipients.add("testcontactgroup@mydomain.com");//"return" mail "the email address entered couldn't found." email.subject = "mysubject"; email.body = new messagebody("mybody"); // send mail email.send();
if i'm trying send testcontactgroup
i'm got exception:
"at least 1 recipient isn't valid."
and if i'm trying send testcontactgroup@mydomain.com
i'm got email mail isn't found.
so, how can send email group list i'm crated? or way create distribution list ews?
thanks
problem solved.
i'm need add group id follow:
mycontactgroup.id = grpid;
i'm group id follow:
// instantiate item view number of items retrieve contacts folder. itemview view = new itemview(9999); // request items in contacts folder have properties selected. finditemsresults<item> contactitems = service.finditems(wellknownfoldername.contacts, view); string groupid = string.empty; list<itemid> groupitemids = new list<itemid>(); // loop through contacts foreach (item item in contactitems) { //check see if contactgroup if (item contactgroup) { //get contact group contactgroup contactgroup = item contactgroup; groupitemids.add(item.id);//using send email item id, can classify displayname etc.. } }
Comments
Post a Comment