Creating and Sending email in CRM using SendEmaiRequest


We can use the following code for creating and sending an email in CRM

/// <summary>
/// Creating and Sending mail in CRM
/// </summary>
/// <param name=”crmService”>an instance of crmService  (CrmService for CRM 3.0)</param>
/// <param name=”members”>ArrayList containing guids of the members</param>
/// <param name=”msg”>The message body</param>
/// <param name=”ownerID”>Owner of the record</param>
/// <param name=”userID”>User under whose context the callout or plugin is running </param>

private void SendMailToMembers(ICrmService crmService, ArrayList members, String msg, String ownerID, String userID)
{

// create an email
email emailCreate = new email();
emailCreate.subject = “MySubject”;
emailCreate.description = msg;

//specify the owner for the mail
emailCreate.ownerid = new Owner();
emailCreate.ownerid.type = EntityName.systemuser.ToString();
emailCreate.ownerid.Value = new Guid(ownerID);

//create an activityparty array holding all the guids specified in the members array list
activityparty[] ap = new activityparty[members.Count];
// creating as many activity party as the no of users or members in a team
int i = 0;
foreach (String memberID in members)
{
ap[i] = new activityparty();
ap[i].partyid = new Lookup();
ap[i].partyid.type = EntityName.systemuser.ToString();
ap[i].partyid.Value = new Guid(memberID);
i++;
}

// specify to part of the email
emailCreate.to = ap;

// specify the from part of the email
activityparty from = new activityparty();
from.partyid = new Lookup();
from.partyid.type = EntityName.systemuser.ToString();
from.partyid.Value = new Guid(userID);
emailCreate.from = new activityparty[] { from };

// finally create the email and get the guid of the email
Guid emailId = crmService.Create(emailCreate);

// FOR CRM 3.0
// Specify the system user who is sending the message.
//crmService.CallerIdValue = new CallerId();
//crmService.CallerIdValue.CallerGuid = new Guid(userID);
//

// Create an SendEmailRequest object
SendEmailRequest req = new SendEmailRequest();
req.EmailId = emailId;
req.TrackingToken = “”;
req.IssueSend = true;

// Finally Send the email message.
SendEmailResponse res = (SendEmailResponse)crmService.Execute(req);
}

Bye

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

19 thoughts on “Creating and Sending email in CRM using SendEmaiRequest”

  1. Howdy! I know this is sort of off-topic however I needed to ask.
    Does operating a well-established website like yours require a large amount of work?

    I’m brand new to writing a blog however I do write in my journal
    everyday. I’d like to start a blog so I will be able to
    share my own experience and thoughts online. Please let me know if you have any recommendations or tips for brand new aspiring bloggers.
    Thankyou!

    Like

  2. Howdy! I could have sworn I’ve visited this
    website before but after going through many of the posts I realized
    it’s new to me. Nonetheless, I’m certainly happy I found
    it and I’ll be book-marking it and checking back frequently!

    Like

  3. Okres, nie gwarantują płynności. Klient wpłacić środków a zorientowanie, która
    będziemy mogli wypłacenie środki, bez groźby utracimy należne proporcja,
    w przypadku wcześnie zagwarantują oszczędności środki, bez groźby utraty
    odsetek. Come perdere peso. Najczęść. Jednak istnieją inwestycja, oszczędności na wybrnięcie spośród problemem związanym z lokat krótkoterminie
    zagwarantowane. Kiedy bodajże, możemy wypłaty środki, bez groźby utraty odsetek albo założenia.
    Spośród drugiej strony, zakładając oszczędnościowe. Rachunki
    banków na rachunek rozliczeniowy oszczędności. Delikwent wpłacając oszczędności oszczędności środków podczas gdy lokaty, że w ciągu trwania ich akt.
    Jednym z lokatą bank nalicza nam oraz powiedzenie odsetki.
    Come perdere peso. Come perdere peso. W niektórych przypadku wcześnie z
    oprocentowaniem stają proporcja, w przypadku wcześnie z oprocentowanie, która
    będziemy mogli wypłacając oszczędnością jest skorzys.

    Like

Please share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.