protected void btnSend_Click(object sender, EventArgs e) { Page.Validate("vlgEmailForm"); if (Page.IsValid) { Item currentItem = Sitecore.Context.Item; InvokeEM24ContentSharedWithAFriendRequest message = new InvokeEM24ContentSharedWithAFriendRequest { RequestUrl = Request.Url }; message.PMText = txtThoughts.Text.Trim(); message.ToEmail = txtRecipientEmail.Text.Trim(); message.UserContactFirstName = txtYourName.Text.Trim(); message.RequestUrl = Request.Url; string domain = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority); if (currentItem != null) { message.ReminderLink = domain + currentItem.GetUrl(); } BaseReply reply = ExactTargetService.InvokeEM24ContentSharedWithAFriend(message); MembershipManager mmgr = new MembershipManager(); if (IsUserLoggedIn) { try { bool success = mmgr.LogMemberActivity(CurrentMember.MemberId, currentItem.ID.ToGuid(), Constants.UserActivity_Values.Shared, Constants.UserActivity_Types.ContentRelated); } catch { } } pnlConfirmation.Visible = true; pnlForm.Visible = false; } else { validWarning.Visible = true; } }
public static BaseReply InvokeEM24ContentSharedWithAFriend(InvokeEM24ContentSharedWithAFriendRequest request) { BaseReply reply = new BaseReply(); SoapClient client = ExactTargetService.GetInstance(); StringBuilder sbReturnString = new StringBuilder(); Guid preferredLanguage = request.PreferredLanguage; int emailTemplateID = GetEmailTemplateId(preferredLanguage, Constants.EmailIDs.EM24ContentSharedWithAFriendENID, Constants.EmailIDs.EM24ContentSharedWithAFriendSPID); try { //Create a GUID for ESD to ensure a unique name and customer key TriggeredSendDefinition tsd = ExactTargetService.GetSendDefinition(Guid.NewGuid().ToString(), emailTemplateID, request.ToEmail, "content shared with a friend"); string cStatus = ExactTargetService.GetCreateResult(ref client, tsd, ref sbReturnString); if (cStatus == "OK") { tsd.TriggeredSendStatus = TriggeredSendStatusEnum.Active; //necessary to set the TriggeredSendDefinition to "Running" tsd.TriggeredSendStatusSpecified = true; //required string uStatus = ExactTargetService.GetUpdateResult(ref client, tsd, ref sbReturnString); if (uStatus == "OK") { // *** SEND THE TRIGGER EMAIL Subscriber newSub = new Subscriber(); newSub.EmailAddress = request.ToEmail; newSub.SubscriberKey = request.ToEmail; etAPI.Attribute tempAttribute; List<etAPI.Attribute> AttributeList = new List<etAPI.Attribute>(); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "domain_link"; tempAttribute.Value = request.RequestUrl.Scheme + "://" + request.RequestUrl.Authority; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "content_helpfulness_and_comments_module"; tempAttribute.Value = request.ContentHelpfulnessAndCommentsModule; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "pm_text"; tempAttribute.Value = request.PMText; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "reminder_image"; tempAttribute.Value = request.ReminderImage; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "reminder_link"; tempAttribute.Value = request.ReminderLink; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "reminder_summary"; tempAttribute.Value = request.ReminderSummary; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "reminder_title"; tempAttribute.Value = request.ReminderTitle; AttributeList.Add(tempAttribute); tempAttribute = new etAPI.Attribute(); tempAttribute.Name = "user_contact_first_name"; tempAttribute.Value = request.UserContactFirstName; AttributeList.Add(tempAttribute); newSub.Attributes = AttributeList.ToArray(); ExactTargetService.SendEmail(ref client, tsd, ref sbReturnString, newSub); reply.Successful = true; } } } catch (Exception exc) { string message = "Unable to send welcome email."; reply.Successful = false; reply.Message = message; Log.Error(exc.ToString(), "something went wrong"); } return reply; }