CRM operation email

Source: Internet
Author: User
Tags microsoft dynamics

Using system;
Using Microsoft. xrm. SDK;
Using Microsoft. CRM. SDK. messages;
Using Microsoft. xrm. SDK. query;

/// <Summary>
/// Email
/// </Summary>
Public class emailhelper
{
Public static readonly string entityname = "email ";
Public guid emailid = guid. empty;
Public iorganizationservice service;

/// <Summary>
/// Create an email
/// </Summary>
Public void create ()
{
Entity en = new entity ();
En ["subject"] = "email test ";
En ["activityid"] = guid. newguid ();
Emailid = service. Create (en );
}

/// <Summary>
/// Send an email Asynchronously
/// </Summary>
/// <Param name = "query"> query conditions </param>
Public void backgroundsendemail (querybase query)
{
Backgroundsendemailrequest request = new backgroundsendemailrequest ();
Request. query = query;
Backgroundsendemailresponse response = (backgroundsendemailresponse) service. Execute (request );
Entitycollection = response. entitycollection;
Bool [] hasattachments = response. hasattachments;
}

/// <Summary>
/// Check whether incoming emails should be upgraded to Microsoft Dynamics CRM System
/// </Summary>
/// <Param name = "messageid"> message id </param>
/// <Param name = "subject"> topic </param>
Public void checkpromoteemail (string messageid, string subject)
{
Checkpromoteemailrequest request = new checkpromoteemailrequest ();
Request. messageid = messageid;
Request. Subject = subject;
Checkincomingemailresponse response = (checkincomingemailresponse) service. Execute (request );
Int reasoncode = response. reasoncode;
Bool shoulddeliver = response. shoulddeliver;
}

/// <Summary>
/// Send batch emails
/// </Summary>
/// <Param name = "query"> query conditions </param>
/// <Param name = "templateid"> template id </param>
Public void sendbulkmail (querybase query, guid templateid)
{
Whoamirequest emailsenderrequest = new whoamirequest ();
Whoamiresponse emailsenderresponse = service. Execute (emailsenderrequest) as whoamiresponse;
Sendbulkmailrequest request = new sendbulkmailrequest ();
Request. query = query;
Request. Sender = new entityreference () {logicalname = "systemuser", id = emailsenderresponse. userid };
Request. requestid = guid. empty;
Request. regardingtype = "systemuser ";
Request. templateid = templateid;
Sendbulkmailresponse response = (sendbulkmailresponse) service. Execute (request );
}

/// <Summary>
/// Use the template to send an email
/// </Summary>
/// <Param name = "userid"> sender, user id </param>
/// <Param name = "contractid"> recipient and contact id </param>
/// <Param name = "templateid"> template id </param>
Public void sendemailfromtemplate (guid userid, guid contractid, guid templateid)
{
Entity fromen = new entity () {logicalname = "systemuser", id = userid };
Entity toen = new entity () {logicalname = "contract", id = contractid };
Entity emailen = new entity () {logicalname = entityname };
Emailen ["from"] = new entity [] {fromen };
Emailen ["to"] = new entity [] {toen };
Emailen ["subject"] = "email sending test ";
Emailen ["directioncode"] = true;
Sendemailfromtemplaterequest request = new sendemailfromtemplaterequest ();
Request. Target = emailen;
Request. templateid = templateid;
Request. regardingid = contractid;
Request. regardingtype = "contract ";
Sendemailfromtemplateresponse response = (sendemailfromtemplateresponse) service. Execute (request );
Guid id = response. ID;
}

/// <Summary>
/// Send an email
/// </Summary>
Public void sendemail ()
{
Sendemailrequest request = new sendemailrequest ();
Request. emailid = emailid;
Request. issuesend = true;
Request. trackingtoken = "";
Sendemailresponse response = (sendemailresponse) service. Execute (request );
String subject = response. subject;
}

/// <Summary>
/// Obtain the key used to encrypt or decrypt the email creden of users or queues stored in the Microsoft Dynamics CRM Database
/// </Summary>
Public void getdecryptionkey ()
{
Getdecryptionkeyrequest request = new getdecryptionkeyrequest ();
Getdecryptionkeyresponse response = (getdecryptionkeyresponse) service. Execute (request );
String key = response. Key;
}

/// <Summary>
/// Delete the email
/// </Summary>
Public void Delete ()
{
Service. Delete (entityname, emailid );
}
}

CRM operation email

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.