Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Paul Sørensen 304 posts 650 karma points
    Feb 14, 2011 @ 23:22
    Paul Sørensen
    0

    RenderTemplate problem - Error generating macroContent

     

    Hi 

    After upgrading to 4.6.1 I suddenly have this problem with RenderTemplate. I'm pretty sure the problem comes in this line of code

     

                     Context.Server.Execute(string.Format("/default.aspx?umbPageID={0}{1}", PageId, queryString), sw);

    The string returned from RenderTemplate(int) is:
     Error generating macroContent: 'System.Web.HttpException (0x80004005): Error executing child request for /default.aspx. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Web.HttpException (0x80004005): Server cannot append header after HTTP headers have been sent.
    Any ideas?
    Paul S

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 15, 2011 @ 00:05
    Lee Kelleher
    0

    Hi Paul,

    Where are you calling RenderTemple from?  I found that I couldn't use it within XSLT macros - but it worked fine from a user-control macro.

    Cheers, Lee.

  • Medjeti 75 posts 126 karma points
    Feb 15, 2011 @ 00:34
    Medjeti
    0

    Hey guys,

    I'm struggling with the exact same problem and I would LOVE to make some progress.

    I'm messing around with Nibble's Mass Mailer package (modified as per the third to last comment to make it work under Umbraco 4.5+ / .NET 4.0).

    For reasons unbeknownst to man the "Send single e-mail" function works as a charm, while the "Send mass e-mail" doesn't fail but sends an e-mail containing the stack trace of the above mentioned error.

    Here's the string that's returned:

    System.Web.HttpUnhandledException (0x80004005): Exception of type 
    'System.Web.HttpUnhandledException' was thrown. ---> 
    System.Web.HttpException (0x80004005): Server cannot append header after
     HTTP headers have been sent. at 
    System.Web.HttpResponse.AppendHeader(String name, String value) at 
    umbraco.UmbracoDefault.OnInit(EventArgs e) at 
    System.Web.UI.Control.InitRecursive(Control namingContainer) at 
    System.Web.UI.Page.ProcessRequestMain(Boolean 
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at 
    System.Web.UI.Page.HandleError(Exception e) at 
    System.Web.UI.Page.ProcessRequestMain(Boolean 
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at 
    System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,
     Boolean includeStagesAfterAsyncPoint) at 
    System.Web.UI.Page.ProcessRequest() at 
    System.Web.UI.Page.ProcessRequest(HttpContext context) at 
    System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, 
    TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, 
    VirtualPath path, VirtualPath filePath, String physPath, Exception 
    error, String queryStringOverride) at 
    System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, 
    TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, 
    VirtualPath path, VirtualPath filePath, String physPath, Exception 
    error, String queryStringOverride) at 
    System.Web.HttpServerUtility.Execute(String path, TextWriter writer, 
    Boolean preserveForm) at umbraco.library.RenderTemplate(Int32 PageId)' 
    -->

    I've been scouring through Tim's source code and I cannot for the life of me figure out why "Single" should work and "Mass" not.

    Any ideas are greatly appreciated!

  • Paul Sørensen 304 posts 650 karma points
    Feb 15, 2011 @ 10:28
    Paul Sørensen
    0

    Hi

    Unfortunately it's the exact same prolem as Medjeti. I have been elaborating on the Mass Mailer to fix various problems and it has been working fine until 4.6.1 but now it fails. I took out the code from the Umbraco library and found the error in the code line showed in my first post

    /Paul S

  • Medjeti 75 posts 126 karma points
    Feb 15, 2011 @ 10:44
    Medjeti
    0

    Well, I've made a bit of headway:

    The error seems to occur when Library.SendMailFromPageToMember() is called from the ProgressBar1_RunTask() event handler (not btnSendMass_Click() as you'd think).

    This is the handler for the EO.Web progress bar, which apparently does some flushing / respons'ing back and forth which causes RenderTemplate() to break.

    A temporary solution seems to be: Remove the <eo:ProgressBar> tag (mailing.aspx, line 189) - this will cause the dialog to do a proper post-back instead of the Ajax stuff. The post-back will be handled from the btnSendMass_Click() event handler which seems to work.

    I haven't tested this thoroughly at all, but it seemed to work late last night. Gimme a shout when you fixed it and have a working build to share :o)

  • Paul Sørensen 304 posts 650 karma points
    Feb 15, 2011 @ 23:28
    Paul Sørensen
    0

    Hi

    I don't quiet follow you here unless you mean just call the logic in the eventhandler for the ProgressBar1_RunTask

    If you mean something else could you please clarify

    /Paul S

  • Medjeti 75 posts 126 karma points
    Feb 16, 2011 @ 10:26
    Medjeti
    0

    Hey Paul,

    As far as I can gather, using the <eo:ProgressBar> overrides the post-back event and uses the ProgressBar1_RunTask() event handler instead of btnSendMass_Click().

    For some reason, calling RenderTemplate() from ProgressBar1_RunTask() doesn't work, so I've found that you need to disable the <eo:ProgressBar> in order for the btnSendMass_Click() logic to kick in.

    This means you won't have your nice progress bar, but at least you'll have a functioning mail script.

    Hope that's a bit more clear... :o)

  • Paul Sørensen 304 posts 650 karma points
    Feb 17, 2011 @ 09:25
    Paul Sørensen
    1

    Hi

    I thought the progress bar was worth fighting for so I finally found a solution.

    I did this in Page_load

     

                    int pageId = int.Parse(Request["id"], CultureInfo.InvariantCulture);
                    string body = umbraco.library.RenderTemplate(pageId);
                    HttpContext.Current.Cache.Insert("body", body);
    and then this in ProgressBar1_RunTask
                    if (HttpContext.Current.Cache["body"] == null)
                        throw new InvalidOperationException("No boy was created");
                    string mailBody = HttpContext.Current.Cache["body"].ToString();
    Then I avoid the RenderTemplate in the ProgressBar1_RunTask.
    My MailEingine doesn't look quiet as the original one - I did some rewriting to come around danish characters and resource problems
    Hope it helps other to get in
    /Paul S

     

  • Medjeti 75 posts 126 karma points
    Feb 17, 2011 @ 14:40
    Medjeti
    0

    Hey Paul,

    Fantastic work, thanks for sharing!

    Can you elaborate on the character problems you had? Easy to fix?

  • Paul Sørensen 304 posts 650 karma points
    Feb 20, 2011 @ 17:19
    Paul Sørensen
    0

    Here's my Send method

           public void SendMessage(string fromAddress, string toAddress, string subject, string body, int cnt)
            {
                if (string.IsNullOrEmpty(fromAddress))
                    throw new ArgumentNullException("fromAddress");
                if (string.IsNullOrEmpty(toAddress))
                    throw new ArgumentNullException("toAddress");
                if (string.IsNullOrEmpty(subject))
                    throw new ArgumentNullException("subject");
                if (string.IsNullOrEmpty(body))
                    throw new ArgumentNullException("body");
    
                try
                {
                    using (SmtpClient client = new SmtpClient())
                    {
                        using (MailMessage message = new MailMessage())
                        {
                            message.Subject = subject;
                            message.IsBodyHtml = false;
                            message.Body = "You need an HTML capable mail client to see this message.";
    
                            message.From = new MailAddress(fromAddress.Trim());
                            message.To.Add(new MailAddress(toAddress.Trim()));
    
                            message.BodyEncoding = Encoding.UTF8;
                            message.SubjectEncoding = Encoding.UTF8;
    
                            System.Net.Mime.ContentType mimeType = new System.Net.Mime.ContentType("text/html; charset=utf-8");
    
                            using (AlternateView item = 
                                AlternateView.CreateAlternateViewFromString(body, mimeType))
                            {
                                foreach (KeyValuePair<string, string> pair in this.resources)
                                {
                                    string imageName = pair.Key;
                                    string ext = Path.GetExtension(imageName).Replace(".", ""); // I know it's there
                                    string path = HttpContext.Current.Server.MapPath(imageName);
                                    LinkedResource resource = new LinkedResource(path, "image/" + ext.ToLower().Replace("jpg", "jpeg"));
                                    resource.ContentId = pair.Value;
                                    item.LinkedResources.Add(resource);
                                }
                                message.AlternateViews.Add(item);
    
                                string receiver = message.To[0].Address;
                                //message.To.Clear();
                                //message.To.Add(new MailAddress("[email protected]"));
                                client.Send(message);
                                Helper.LogCustom("Mail {1} has been send to: {0}", receiver, cnt);
                            }
                        }
                    }
                }
                catch (SmtpFailedRecipientsException ex)
                {
                    for (int i = 0; i < ex.InnerExceptions.Length; i++)
                    {
                        SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
                        if (status == SmtpStatusCode.MailboxBusy ||
                            status == SmtpStatusCode.MailboxUnavailable)
                        {
                            Helper.LogError("No recipients specified");
                        }
                        else
                        {
                            Helper.LogError("SMTP: Failed to deliver message to {0} - {1}",
                                ex.InnerExceptions[i].FailedRecipient,
                                ex.InnerExceptions[i]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Helper.LogError("GENERAL: Failed to deliver message to {0} - {1}",
                        toAddress, ex);
                }
            }
    

     

    Hope you can use it - and thanks for your assistance

    /Paul S

  • Medjeti 75 posts 126 karma points
    Feb 22, 2011 @ 01:06
    Medjeti
    0

    Excellent, thanks for sharing - you rock! :o)

    You may want to mark your topic as resolved for future reference.

  • Paul Sørensen 304 posts 650 karma points
    Feb 22, 2011 @ 08:35
    Paul Sørensen
    0

    How do I mark it as resolved?

    /Paul S

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Feb 22, 2011 @ 08:38
    Simon Dingley
    0

    Click the tick on the post that you want to mark as the solution.

    Simon

  • Paul Sørensen 304 posts 650 karma points
    Feb 22, 2011 @ 13:21
    Paul Sørensen
    0

    Thanks finally got it - has to be on a respons from someone else then me

    /Paul S

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Feb 22, 2011 @ 13:31
    Simon Dingley
    0

    Yes unfortunately which is a PITA for others when you end up answering your own question because you can't mark the real solution for the benefit of others.

  • Medjeti 75 posts 126 karma points
    Mar 14, 2011 @ 23:42
    Medjeti
    0

    Hey Paul,

    Sorry to revive an old thread but I just encountered the (apparently well-known) encoding issue regarding Danish / non-ascii characters.

    I added the BodyEncoding and SubjectEncoding properties as per your example - things are fine in desktop clients such as Outlook, but webmail clients seem to act up. Did you - or anybody else - manage to resolve this?

    Cheers,
    /Mikael

  • Patrick 2 posts 22 karma points
    Mar 15, 2011 @ 02:01
    Patrick
    0

    @Medjeti:

    Your trick deleting <eo:ProgressBar /> worked fine. However Paul's solution is not clear to me. Did you test Paul's solution? If so, could you please post the entire mailing.aspx as well as mailing.aspx.cs? You'd really help me out on that.

    Tnx in advance!

  • Paul Sørensen 304 posts 650 karma points
    Mar 15, 2011 @ 13:20
    Paul Sørensen
    0

    @Medjeti:

    I have no problems in with the danish characters in the mails I produce when reading them in ex. Google mail.

    /Paul S

  • Medjeti 75 posts 126 karma points
    Mar 16, 2011 @ 01:39
    Medjeti
    0

    @Paul: I see now Gmail displays the characters correctly, however one.com webmail does not. Oh well, one of those things I guess...

    @Patrick: I didn't take time to tidy things up, so it's not exactly pretty - but at least it works...

    http://dl.dropbox.com/u/4147537/mailing.aspx
    http://dl.dropbox.com/u/4147537/mailing.aspx.cs

    Did you update the project referencing the .NET 4.0 version of EO.Web? Check happyfanaticsalser'c omment on http://www.nibble.be/?p=63 ;

    Hope that helps!

    /Mikael

  • Patrick 2 posts 22 karma points
    Mar 17, 2011 @ 14:34
    Patrick
    0

    @Medjeti:

     

    Thanks a lot, this worked like a charm! I had to alter lines107-109 Library.cs as well from:

            public static void SendMailFromPageToMember(string FromMail, Member member, string Subject, int PageId)
            {
                string body = umbraco.library.RenderTemplate(PageId);

    to:

            public static void SendMailFromPageToMember(string FromMail, Member member, string Subject, string body)
            {
                //string body = umbraco.library.RenderTemplate(PageId);

     

    The character problem - in Dutch we use some special characters, for instance: &euml; - I solved by setting everything to UTF-8. This means adding this metaline to the newsletter's template as well:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  • Julius Bartkus 51 posts 76 karma points
    May 03, 2011 @ 16:24
    Julius Bartkus
    0

    @Medjeti:

    can you post the files again?:) the links above doesn't work anymore

    Thanks :)


  • Medjeti 75 posts 126 karma points
    May 04, 2011 @ 18:35
    Medjeti
    0

    Yup yup, files are back up.

Please Sign in or register to post replies

Write your reply to:

Draft