Developer forum

Forum » Integration » Integration with CRM

Integration with CRM

Bjørn Ingebrigtsen
Reply

Hi

The function GetEmailsInfo in Dynamicweb.DataIntegration.Providers.CRMProvider seems to only return emails that was opened in a browser. I would like to get all emails that was sent according to the integration job setup (Export emails since) regardless of if they were opened, links clicked etc. Is there any way to do this?

Bjørn

Replies

 
Dmitriy Benyuk
Reply

Hi Bjørn,
no that is not implemented. As a possible solution for now could be to use the Dynamicweb api and write your own method to return you all emails.
To get emails you can use:
Email.GetUpdatedEmailsFromLastExport().Where(e => e.IsEmailSent() && e.GetEmailSentStartTime() > emailsSentFromTime);
Or
emails = Email.GetEmails(true).Where(e => e.IsEmailSent() && e.GetEmailSentStartTime() > emailsSentFromTime);

Then you can get the EmailInfos and fix the sample code for your needs:

internal static List<EmailInfo> GetEmailsInfo(bool exportNotExportedEmails, DateTime emailsSentFromTime)
        {
            List<EmailInfo> ret = new List<EmailInfo>();
            //todo: write your own GetEmails:
            IEnumerable<Email> emails = GetEmails();
            EmailStatistics stat = null;

            foreach (Email e in emails)
            {
                if (e != null)
                {
                    stat = new EmailStatistics(e);

                    foreach (ResponseItem ri in stat.GetResponses())
                    {
                        EmailInfo ei = new EmailInfo();
                        ei.ExternalUserID = ri.AccessUserExternalID;
                        ei.EmailID = e.ID;
                        ei.EmailSubject = ri.EmailSubject;
                        ei.EmailSendCompleteDate = e.GetEmailSentCompletedTime();
                        ei.ClickedLinks.Add(ri.Data);
                        
                        ret.Add(ei);
                    }
                }
            }
            //todo:
            //merge your list with having EmailInfo for the same users "AccessUserExternalID":
            //EmailInfo.ClickedLinks collection can be merged and duplicate EmailInfo's can be deleted

            return ret;
        }

Namespaces needed:
using Dynamicweb.EmailMarketing;
using Dynamicweb.EmailMarketing.Statistics;
using Dynamicweb.Mailing;
using Dynamicweb.Mailing.Links;

Regards, Dmitrij

 
Bjørn Ingebrigtsen
Reply

Dmitrij,

Thank you for a quick response. I am able to get the all the emails, but there is no Response for emails that did not get opened, so I am unable to get the AccessUserExternalID (who it was sent to) using the stat.GetResponses() call. 

Bjørn

 

 

 
Bjørn Ingebrigtsen
Reply

Dmitrij,

Did you have a chance to look at this? Since some emails will never be opened, they do not have a response, so I am unable to get the AccessUserExternalID. Is there another way to do it? The export to CRM expects to connect it to a CRM contact.

Bjørn

 

 
Dmitriy Benyuk
Reply

Hi Bjørn,
you can get the AccessUserExternalID by finding a user with AccessUserId that equals to the emails recipients "RecipientKey" value.

If that solution works for you here is some code to get the email recipients:
foreach (Email e in emails)
            {
                if (e != null)
                {
                    helper = new ExportStatisticsHelper(e);
                    if (helper != null)
                    {
                        foreach (RecipientsListData rld in helper.GetRecipientsListData())
                        {
                            if (rld != null)
                            {
                                rcp = Recipient.GetRecipientById(rld.Id);
                                if (rcp != null)
                                {
                                    row = new Dictionary<string, object>();
                                    //rcp.RecipientKey - should match the AccessUserId
                                    row.Add("EmailID", e.ID);
                                    row.Add("RecipientID", rld.Id);
                                    row.Add("Recipient", rcp.Name);                                    
                                    row.Add("Email", rcp.EmailAddress);
                                    row.Add("Opened", rld.Opened);
                                    row.Add("Clicked", rld.Clicked);
                                    row.Add("Cart", rld.Cart);
                                    row.Add("Order", rld.Order);
                                    row.Add("Unsubscribed", rld.Unsubscribed);
                                    row.Add("EngagementIndex", rld.EngagementIndex);
                                    row.Add("ExternalID", GetExternalUserID(rcp.RecipientKey));
                                    dataList.Add(row);
                                }
                            }
                        }
                    }
                }
            }
Regards, Dmitrij

 
Bjørn Ingebrigtsen
Reply

Thanks!

I am not able to find the method "GetExternalUserID" method. In what namespace is it located?

Bjørn

 
Dmitriy Benyuk
Reply

Sorry, here it is:
private static string GetExternalUserID(string userID)
        {
            string ret = string.Empty;
            int id;
            if (int.TryParse(userID, out id))
            {
                User user = User.GetUserByID(id);
                if (user != null)
                {
                    ret = user.ExternalID;
                }
            }
            return ret;
        }

 
Bjørn Ingebrigtsen
Reply

Awesome!

I am now able to export all emails.

Bjørn

 

You must be logged in to post in the forum