Export (0) Print
Expand All
Expand Minimize

SendEmail Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online and offline

Sends an e-mail message.

The relevant classes are specified in the following table.



To use this message, pass an instance of the SendEmailRequest class as the request parameter in the Execute method.

To perform this action, the caller must have access rights on the e-mail entity instance. For a list of required privileges, see SendEmail Privileges.


The following code shows how to use the SendEmail message.

// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create a SendEmail request.
SendEmailRequest req = new SendEmailRequest();
req.EmailId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC");
req.TrackingToken = "";
req.IssueSend = true;

// Send the e-mail message.
SendEmailResponse res = (SendEmailResponse)service.Execute(req);
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Need system user ID for activity party.
Dim systemUserRequest As New WhoAmIRequest()
Dim systemUser As WhoAmIResponse = CType(service.Execute(systemUserRequest), WhoAmIResponse)

' Create an activity party for the email
Dim party As New activityparty()
party.partyid = New Lookup()
party.partyid.type = EntityName.systemuser.ToString()
party.partyid.Value = systemUser.UserId

' Create an email message.
Dim email As New email()

' Set email properties
email.to = New activityparty() { party }
email.from = New activityparty() { party }
email.subject = "Please disregard"
email.description = "This is a test message. Please disregard"

Dim direction As New CrmBoolean()
direction.Value = True
email.directioncode = direction

Dim targetCreate As New TargetCreateEmail()
targetCreate.Email = email

Dim request As New CreateRequest()
request.Target = targetCreate

Dim response As CreateResponse = CType(service.Execute(request), CreateResponse)
Dim emailID As Guid = response.id

' Create a SendEmail request.
Dim req As New SendEmailRequest()
' SDK:req.EmailId = new Guid("A0F2D8FE-6468-DA11-B748-000D9DD8CDAC");
req.EmailId = emailID
req.TrackingToken = ""
req.IssueSend = True

' Send the email message.
Dim res As SendEmailResponse = CType(service.Execute(req), SendEmailResponse)

See Also



© 2010 Microsoft Corporation. All rights reserved.

© 2015 Microsoft