Last couple of days I was buried in ECM code debug.
Some tips for future:
0. Processing is different for HTML mail and Newsletter. First one is regulated by HtmlMail, second one by WebPageMail. Both have one base class HtmlMailBase.
1. "Message Preview" composes an url and downloads it - to present you an actual email. Actions are the same as if you dispatch this email. This is relevant for WebPageMail, where HtmlMail just takes "Body" field value from message item.
2. Link to download an email is very easy to understand:
http://hostname/?sc_itemid=%7b9121BA1E-619A-4B84-BCB9-A1806F117810%7d&sc_lang=en&sc_device=%7bFE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3%7d&sc_mode=normal&sc_database=master&ec_recipient=sitecore%5cAdmin&ec_id=9033D12313D74836A7D5CECD015A3E82
http://hostname - equal to WebUtil.GetServerUrl(Context.Request.Url). You may check it in httpRequestBegin to make sure that correct hostname is resolved.
sc_itemid,sc_lang,sc_device,sc_mode,sc_database - properties of item that is chosen in "Body" ("Web Page") field of newsletter item. By default it is Newsletter Root under your newsletter item.
ec_recipient, ec_id - ECM properties, name of mail's PersonalizationContact and global EcmId.
3. When you put some links into the content, they are also transformed - sc_camp and ec_as are added there. sc_camp is email campaign ID, ec_as is ID of automation state (one of stored in AutomationStates table in Analytics db). More in Sitecore.Modules.EmailCampaign.HtmlMailBase.ModifyHrefLink
Lately, when user clicks some links, ec_as is processed for Analytics purposes, and as a nice tip, you may get current username using AnalyticsHelper.GetRecepient.
4. Tokens like $email$, $phone$ can be placed anywhere, even in links. Links are processed lately then tokens are replaced with actual values. One may define its own tokens in item, that is defined by ECM Manager root, Default Subscriber profile.
5. There are different URLs used by ECM. One is the url that you are launching Sitecore from - Context.Request.Url, and other is ECM Manager root setting BaseUrl. First is used to create this magic "DownloadLink" for message, second is used to create links inside a message.
6. Magical RegisterEmailOpened.aspx page, that is a source for 1-pixel image inserted in message automatically, returns 404 anyway and is used only for tracking purposes.
Hej Kate,
ReplyDeleteIn tip 3. you say that you can get the current username through the AutomationStates. If you f. ex. click the unsubscribe from newsletter link in you newsletter then you get to page that will contain the sc_camp and ec_as in the query string.
How you there get the recipient based on that information. Do you have any snippet for that?
Hi alin_ms,
DeleteJust as I said, you should be able to use AnalyticsHelper.GetRecipient to get the recipient:
string stateParam = Context.Request.QueryString[GlobalSettings.AutomationStateQueryKey];
if (!string.IsNullOrEmpty(stateParam) && ShortID.IsShortID(stateParam))
{
string messageId;
Guid stateId;
string recipient = AnalyticsHelper.GetRecipient(new Guid(stateParam), out messageId, out stateId);
if (!string.IsNullOrEmpty(recipient) && ID.IsID(messageId))
{
Contact contact = Util.GetContactFromName(recipient);
}
}
And "contact" should give you the info you need.
Please check if it works for you.