Edit Newsletter\widget.ascx.cs code help

Jan 19, 2011 at 3:30 PM
Edited Jan 19, 2011 at 4:43 PM

I am trying to put this code from BE 1.6 in BE 2.0 but the code is different and I am not sure where to insert the red text. Thank you.

 

 1.6 code

 private static MailMessage CreateEmail(Post post)
    {
        MailMessage mail = new MailMessage();
        mail.Subject = post.Title;
        mail.Body = "There'a new review available.<br /> <a href=\"" + post.AbsoluteLink + "\">" + post.Title + "</a><br />";
        mail.Body += post.Description;
        mail.Body += "<hr />";
        mail.Body += "Thank you for your interest and support, please refer your book reading friends to ";
        mail.Body += "<a href=\"" + Utils.AbsoluteWebRoot + "\">" + Utils.AbsoluteWebRoot + "</a>";
        mail.From = new MailAddress(BlogSettings.Instance.Email, BlogSettings.Instance.Name);
        return mail;
    }

2.0 code
 private static MailMessage CreateEmail(IPublishable publishable)
        {
            var mail = new MailMessage
                {
                    Subject = publishable.Title,
                    Body = FormatBodyMail(publishable), 
                    From = new MailAddress(BlogSettings.Instance.Email, BlogSettings.Instance.Name)
                };
            return mail;
        }

 

Jan 20, 2011 at 12:53 AM

Take a look at this section in the same file

/// <summary>
        /// Replace tags below in newsletter.html theme
        ///     [TITLE]
        ///     [LINK_DESCRIPTION]
        ///     [LINK]
        ///     [WebRoot]
        ///     [httpBase]
        /// </summary>
        /// <param name="post">
        /// The post to format.
        /// </param>
        /// <returns>
        /// The format body mail.
        /// </returns>
        private static string FormatBodyMail(Post post)
        {
            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);
            return body.ToString();
        }
Looks like there is not an html file in the themes folder that creates the email body.  Try sending yourself a notice from the newsletter widget and then edit as needed.

Jan 20, 2011 at 1:08 AM
Edited Jan 20, 2011 at 2:36 AM

The code goes in this file, the issue is it is different than what I used in 1.6 as my post suggests.

Newsletter/widget.ascx.cs

Jan 20, 2011 at 3:25 AM
Edited Jan 20, 2011 at 3:44 AM

It is handeled differently in 2.0.  Look in the folder /themes/Standard/newsletter.html. You will see the newletter.html file.  You can edit this file and then save it to your theme folder and any and all text you want in the email there.  You do not have to amend the .cs file only the newsletter.html file.  This gives you carte blanch to to do what you want.

Hope this helps.

Jan 20, 2011 at 3:54 AM

Thank you , I will give it a try.

Feb 3, 2011 at 5:39 PM

Excuse my ignorance but can anyone help me with what do I complete the following:

Replace tags below in newsletter.html theme
        ///     [TITLE]
        ///     [LINK_DESCRIPTION]
        ///     [LINK]
        ///     [WebRoot]
        ///     [httpBase]
      

soecifically what do I fill in for the webroot and what is http base

Feb 3, 2011 at 6:34 PM

I don't believe you have to change these settings, the email that is went out picks up the post title and description automatically, as well as other settings.  I didn't change anything other then adding some text that I wanted in the email and it works great.

Sep 5, 2012 at 1:57 AM
Edited Sep 5, 2012 at 1:59 AM

Sorry to bring up an old post, but can somebody help a novice? I am trying to hard code a base URL into the outbound email link (to the post). The reason for this is that we have dual servers running and to make sure we update the primary one we have to post under the absolute URL of the primary server which is then copied into the email link rather than the main domain URL.

What I need to update is the [LINK] part of the email template.

So based on that, is it just a case of updaing the urlbase above?

i.e.

var urlbase = Path.Combine(
                Path.Combine(Utils.AbsoluteWebRoot.AbsoluteUri, "themes"), BlogSettings.Instance.Theme);



Becomes

var urlbase = "http://www.maindomain.com/themes/chosentheme";


Or will that have no effect on the actual [LINK]

Would I need to do it directly there instead?


i.e.

body = body.Replace("[LINK]", publishable.AbsoluteLink.AbsoluteUri);



becomes

body = body.Replace("[LINK]", publishable.AbsoluteLink + "http://www.maindomain.com/");



or am I barking up the wrong tree entirely?

Any pointers or help is highly appreciated.

Thanks.

Sep 10, 2012 at 11:17 PM

Anybody?

Sep 13, 2012 at 7:51 AM

Nobody?