Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, 17 March 2017

Send a Custom E-mail for a Campaign Activity

The following sample shows how to send an e-mail for a campaign activity.
 
[C#]
public void SendEmail(Guid campaignActivityID)
{
   CrmService service = new CrmService();
   service.Credentials = 
      System.Net.CredentialCache.DefaultCredentials;

   service.CallerIdValue = new CallerId();
   // Replace the GUID with the GUID of your Microsoft Dynamics CRM
   // Administrator.
   service.CallerIdValue.CallerGuid =
      new Guid("FD80F8E8-C852-DA11-B1FB-0007E94D105B");

   SendEmailRequest req = new SendEmailRequest();
   req.EmailId = campaignActivityID;
   req.TrackingToken = "";
   req.IssueSend = true;

   try 
   {
      SendEmailResponse res =
         (SendEmailResponse)service.Execute(req);
   }
   catch (System.Web.Services.Protocols.SoapException er)
   {
      //Process any error messages here.
   }
}
 


Create CRM Organization

public class CreateCrmOrg
{
       public CreateCRM_Org()
       {
        static void Main()
        {
               DeploymentServiceClient service = Microsoft.Xrm.Sdk.Deployment.Proxy
                      .ProxyClientHelper.CreateClient(new Uri("http://srv-crm04/XRMDeployment/2011/Deployment.svc"));
               Console.WriteLine(CreateOrganization(service
                      ,new Organization
                             {
                                   UniqueName = "testOrgProv1",
                                   FriendlyName = "testOrgProv1",
                                   SqlServerName = "SQL1-CRM04",
                                   SrsUrl = "http://SQL1-CRM04/ReportServer",
                                   BaseCurrencyCode = RegionInfo.CurrentRegion.ISOCurrencySymbol,
                                   BaseCurrencyName = RegionInfo.CurrentRegion.CurrencyNativeName,
                                   BaseCurrencySymbol = RegionInfo.CurrentRegion.CurrencySymbol,
                                   State = Microsoft.Xrm.Sdk.Deployment.OrganizationState.Enabled
                             }));
        }           

        Guid? CreateOrganization(IDeploymentService deploymentService,Organization org)
        {
               BeginCreateOrganizationRequest req = new BeginCreateOrganizationRequest
               {
                      Organization = org
               };

               BeginCreateOrganizationResponse resp = deploymentService.Execute(req) as BeginCreateOrganizationResponse;
               return resp != null ? (Guid?)resp.OperationId : null;
        }
              
}