Bir önceki yazımda template kullanarak email atmayı görmüstük.Bu yazım da da template kullanmadan basit mail atmayı anlatacagım.
Not:Bir önceki yazımda bu classın nasıl kullanılacagı bulunmaktadır.
public static Boolean EmailAt(IOrganizationService service,Guid fromUserId,Guid toContactId)
{
try
{
Boolean atildiMi = false;
// Create the 'From:' activity party for the email
ActivityParty fromParty = new ActivityParty
{
PartyId = new EntityReference(SystemUser.EntityLogicalName, fromUserId)
};
// Create the 'To:' activity party for the email
ActivityParty toParty = new ActivityParty
{
PartyId = new EntityReference(Contact.EntityLogicalName, toContactId)
};
//"Created activity parties."
// Create an e-mail message.
Email email = new Email
{
To = new ActivityParty[] { toParty },
From = new ActivityParty[] { fromParty },
Subject = "Quote Ready",
Description = "SDK Sample for SendEmail Message.",
DirectionCode = true
};
Guid _emailId = service.Create(email);
// Use the SendEmail message to send an e-mail message.
SendEmailRequest sendEmailreq = new SendEmailRequest
{
EmailId = _emailId,
TrackingToken = "",
IssueSend = true
};
//"Sent the e-mail message."
SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);
atildiMi = sendEmailresp !=null ? true :false;
return atildiMi;
}
catch (Exception)
{
return false;
}
}