Newsletter - Remove Email Link

Jan 22, 2011 at 7:43 PM

I am trying to add an remove link to my emails sent from the newsletter widget.  I have coped some code from here and it work when the link is sent as follow:

<http path to post>?RemoveEmail=<email to remove>.  I have confirmed that this works and does remove the email address from newsletter.xml.

Here is the code:

 

        #region RemoveEmail
        //The will remove the email address from the newsletter.xml file When the link is returned like:
        //blog path/post path?RemoveEmail=(emial to be removed)
        //copied from http://www.bryanavery.co.uk/post/2008/10/21/Newsletter-Enhancements.aspx
        //This works but question is how to get the email address loaded into the remove link automatically.
        protected void Page_Load(object sender, EventArgs e)
        {
            UserControl userControl = (UserControl)sender;
            if (userControl != null)
            {
                if (userControl.Request.QueryString["RemoveEmail"] != null)
                {
                    string email = userControl.Request.QueryString["RemoveEmail"];
                    AddEmail(email);
                }
            }
        }

        #endregion

my question is how to get the email address passed to the newletter.html file.  I have added the below to that file:

<a href="[httpBase]?RemoveEmail=[RemoveEmail]">Click here</a> to be removed from the [httpBase] Newsletter"

I have tried amending the below section as highlighted by that causes and error in the CreateEmail routine(I have struck out my addtions)

        private static string FormatBodyMail(Post post) //, string email)
        {
            var body = new StringBuilder();
            var urlbase = Path.Combine(
                Path.Combine(Utils.AbsoluteWebRoot.AbsoluteUri, "themes"), BlogSettings.Instance.Theme);
            var filePath = string.Format("~/themes/{0}/newsletter.html", BlogSettings.Instance.Theme);
            filePath = HostingEnvironment.MapPath(filePath);
            if (File.Exists(filePath))
            {
                body.Append(File.ReadAllText(filePath));
            }
            else
            {
                // if custom theme doesn't have email template
                // use email template from standard theme
                filePath = HostingEnvironment.MapPath("~/themes/Standard/newsletter.html");
                if (File.Exists(filePath))
                {
                    body.Append(File.ReadAllText(filePath));
                }
                else
                {
                    Utils.Log(
                        "When sending newsletter, newsletter.html does not exist " +
                        "in theme folder, and does not exist in the Standard theme " +
                        "folder.");
                }
            }

            body = body.Replace("[TITLE]", post.Title);
            body = body.Replace("[LINK]", post.AbsoluteLink.AbsoluteUri);
            body = body.Replace("[LINK_DESCRIPTION]", post.Description);
            body = body.Replace("[WebRoot]", Utils.AbsoluteWebRoot.AbsoluteUri);
            body = body.Replace("[httpBase]", urlbase);
           // body = body.Replace("[RemoveEmail]", email );
            return body.ToString();
        }

Does anyone have any ideas how I can get the recievers emial address placed in the [RemoveEmail] in the html document?  

Thanks in advance

 

 

Jan 24, 2011 at 5:00 PM

bump.....anyone????

Coordinator
Jan 24, 2011 at 6:30 PM

If I understood what you trying to accomplish correctly:

1. In the PublishableSaved method, change:

var mail = CreateEmail(publishable); -> var mail = CreateEmail(publishable, node.InnerText);

2. Add parameter to CreateEmail:

private static MailMessage CreateEmail(IPublishable publishable) -> private static MailMessage CreateEmail(IPublishable publishable, string email)

3. Pass email down to format routine:

Body = FormatBodyMail(publishable), -> Body = FormatBodyMail(publishable, email),

4. Add parameter and use it:

private static string FormatBodyMail(IPublishable publishable) -> private static string FormatBodyMail(IPublishable publishable, string email)

Jan 28, 2011 at 12:42 AM

Does the above apply to 1.x versions?  I am using 2.0.  The above var, CreateEmail and formate routines exist but are different.

Essentially, what I am trying to do is add a "remove me" link to the email that is generated by the newsletter widget.  The above 'RemoveEmail' routine will remove the person when a formatted link is used.  I just dont know how to get the email of the person receiving the email so it can be used like [TITLE], [LINK}, etc...

Thanks and rtur, your blogs on porting a site to the BE format was a great help to me.   Thanks.

Feb 5, 2011 at 1:34 AM

rtur,

I look to implement the above suggestions however I do not see these options available as above.  There are some that have same name but different items in parentheses.  Like:

private static MailMessage CreateEmail(IPublishable publishable)

but it reads

private static MailMessage CreateEmail(Post post)

I am trying to make the amendments in the Newsletter/widget.ascx.cs file.

Anyone familiar with how this could be done?

Coordinator
Feb 5, 2011 at 1:53 AM

I was looking at current code, it was changed to use interface (IPublishable) instead of Post since 2.0 released. But it shouldn't make a big difference - you still need to get a handle on email and pass it down to where you want to use it as parameter, or save it as static field visible to all class methods.

Feb 7, 2011 at 2:41 AM

I updated to the most recent source code and implemented the above changes and now it works as desired.  Now I only need to figure out how to get a message to appear like when you unsubscribe from a comment subscription.  Not sure I have the skills to do so but gotta try.