Sending email in CRM through COM API and creating email out communication

By | December 24, 2012

As we all know communications are the backbone of any industry in the world. We all send and receive emails on daily basis. The process of sending mails automated will definitely shade our daily workload. Though, this process cannot be automated as a whole, but surely for the processes that need mails to be sent on a particular event or trigger. For example, if the business process needs to send a mail as soon as a user is registered for some kind of service, the log in credentials is changed etc. The same functionality can be built in the Sage CRM.
One of our clients had a requirement, the CRM user should get an automated email in the below scenarios:

  1. User is enabled for the CRM self-service portal, to inform the user with the same.
  2. The login credentials are changed of the respective user, along with the changed credentials.
  3. The communication should get created in the CRM against the out bound email as it is sent.

We have implemented the same at our end. Please allow me to explain in more detail. You just need to send the parameters to the below function as mentioned and mail will be sent automatically. Here is the list of parameters.

  1. pm_EmailAddress = Email Address to which mail needs to be send.
  2. pm_FullName = Full Name of the Person.
  3. pm_MsgBody = Message content
  4. pm_Subject = Subject line that needs to be in the mail.

Of course you need to have email out functionality enable from within Sage CRM.
function fn_SendEmail(pm_EmailAddress,pm_FullName,pm_MsgBody,pm_Subject)
{
            var myMailObject = eWare.GetBlock(“messageblock”);
            myMailObject.DisplayForm = false;
            myMailObject.mSubject = pm_Subject;
            myMailObject.mBody = pm_MsgBody;
            myMailObject.mAddressFrom = “support@sage.com”;
            myMailObject.mNameFrom = “Sage”;    
            myMailObject.AddRecipient(pm_EmailAddress,pm_FullName,”TO”);
            myMailObject.Mode = 2; //Set Mode to send(2) message is sent immediately.
            myMailObject.Execute();
}
Regarding creation of communication, you can make use of below function. Here you need to follow the below parameters.

  1. pmPersonid =  Person Id for whom communication needs to be created.
  2. pmCompanyid =  Company Id for whom communication needs to be created.
  3. pm_Sumbject = Subject line that needs to be in the mail.
  4. pm_EmailAddress = Email Address to which mail needs to be sent.

function CreateCommunication(pmPersonid,pmCompanyid,pm_Sumbject,pm_EmailAddress)
{
            var sCurrentdate=new Date()      
            var sCommId=”0″;
            var sUserId=”0″;
            sUserId = new String(eWare.GetContextInfo(“User”,”user_userid”));
            if(sUserId==”” || sUserId==”undefined” || sUserId==”null”) sUserId=””;
           
            //’if the mail is send create the communication
            var sCommRec = eWare.CreateRecord(“communication”);
            sCommRec.comm_action =”EmailOut”;
            sCommRec.Comm_Status =”Complete”
            sCommRec.comm_subject = pm_Sumbject;
            sCommRec.Comm_TO = pm_EmailAddress;
            sCommRec.Comm_DateTime = sCurrentdate.getVarDate();
            sCommRec.SaveChanges();
           
            //’get the communication id from the above record created
            sCommId = new String(sCommRec(“Comm_CommunicationId”));
            if(sCommId==”” || sCommId==”NULL” ||sCommId==”undefined”)sCommId=”0″;
           
            //’Also create the record in the communocation link
            var sCommLinkRec = eWare.CreateRecord(“Comm_Link”);
            sCommLinkRec.CmLi_Comm_CommunicationId = sCommId;
            sCommLinkRec.CmLi_Comm_CompanyId = pmCompanyid;
            sCommLinkRec.CmLi_Comm_PersonId = pmPersonid;
            sCommLinkRec.CmLi_Comm_UserId = sUserId;
            sCommLinkRec.SaveChanges();
}
You can make use of the above functions in any ASP page or TLS to achieve the mentioned functionality. Hope this helps!