private void SendEmailFromTemplate()
{
CrmService service = connect();
// Create the 'From:' activity party for the email
activityparty fromParty = new activityparty();
fromParty.partyid = new Lookup();
fromParty.partyid.type = EntityName.systemuser.ToString();
fromParty.partyid.Value = new Guid("4D52A946-AE37-DE11-B372-000C29DF4A76");
// Create the 'To:' activity party for the email
activityparty toParty = new activityparty();
toParty.partyid = new Lookup();
toParty.partyid.type = EntityName.account.ToString();
toParty.partyid.Value = new Guid("B835890F-E23E-DE11-ACC7-000C29DF4A76");
// Create an email message.
email email = new email();
// Set email properties
email.to = new activityparty[] { toParty };
email.from = new activityparty[] { fromParty };
email.subject = "SDK Sample email";
email.description = "SDK Sample for SendEmailFromTemplate Message.";
CrmBoolean direction = new CrmBoolean();
direction.Value = true;
email.directioncode = direction;
TargetSendFromTemplateEmail emailTemplateTarget = new TargetSendFromTemplateEmail();
emailTemplateTarget.Email = email;
SendEmailFromTemplateRequest emailRequest = new SendEmailFromTemplateRequest();
emailRequest.Target = emailTemplateTarget;
// The regarding Id is requried and must be of the same type as the Email Template
emailRequest.RegardingId = new Guid("B835890F-E23E-DE11-ACC7-000C29DF4A76");
emailRequest.RegardingType = EntityName.account.ToString();
// Use a built-in email template of type "contact".
emailRequest.TemplateId = new Guid("B6C38BB9-2423-471D-8B38-E3B99ED80E7A");
SendEmailFromTemplateResponse emailResponse = (SendEmailFromTemplateResponse)service.Execute(emailRequest);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment