locked
Anyone have a crm 4.0 simple send email function? RRS feed

  • Question

  • Hi I need a simple send email function that will add an email to an account activity?

    I have tried a few, but with no luck ;-(

    Thanks in Advance

    Friday, March 19, 2010 6:25 AM

Answers

  • Check below code:

    public void sendEmail(Guid fromGuid, Guid toGuid, string subject, string msgBody)
            {
                try
                {
                    CrmService service = new CrmService();
                    // email from
                    activityparty party = new activityparty();
                    party.partyid = new Lookup();
                    party.partyid.type = EntityName.systemuser.ToString();
                    party.partyid.Value = fromGuid;
    
                    email em = new email();
                    em.from = new activityparty[] { party };
    
                    //email to
                    party = new activityparty();
                    party.partyid = new Lookup();
                    party.partyid.type = EntityName.account.ToString();
                    party.partyid.Value = toGuid;
    
                    em.to = new activityparty[] { party };
                    em.subject = subject;
                    em.description = msgBody;
                    
                    //set regarding 
                    //this will attach the mail to particular account in activities/history in detail section
                    em.regardingobjectid = new Lookup(EntityName.account.ToString(), toGuid);
    
                    SendEmailRequest sendMail = new SendEmailRequest();
                    sendMail.EmailId = service.Create(em);
                    sendMail.TrackingToken = "";
                    sendMail.IssueSend = true;
    
                    //send email
                    service.Execute(sendMail);
                }
                catch (Exception e)
                {
                    throw (e.InnerException);
                }
            }

    - Arvind
    Friday, March 19, 2010 9:50 AM