Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Wouter 49 posts 76 karma points
    Nov 27, 2013 @ 11:18
    Wouter
    0

    404: UCommerce.Transactions.EmailService: Send()

    Hi,

    I hope someone can help me. The e-mail service gives me a 404 when it tries to download the template. When I browse to my e-mail template it pop's up ust fine. I've made sure there is only one domain name set, republished the entire site and checked the domain name on the store settings. No luck so far. The domain name I'm using is: mysite.nl (no www prefix!)

    The code that fails in the UCommerce.dll (Version=3.6.1.13149) is (UCommerce.Transactions.EmailService):

    public virtual string Send(ILocalizationContext localizationContext, EmailProfile profile, string emailTypeName, MailAddress to, System.Collections.Generic.IDictionary<stringstring> templateParameters)
            {
                if (!EmailType.Exists((EmailType x) => x.Name == emailTypeName))
                {
                    throw new ConfigurationErrorsException(string.Format("Could not find an e-mail type named '{0}'. Please make sure that Settings -> E-mails -> Types contains a type called '{0}'.", emailTypeName));
                }
                EmailContent content = profile.GetContent(emailTypeName, localizationContext.CurrentCultureCode);
                if (content == null)
                {
                    throw new ConfigurationErrorsException(string.Format("Cannot find template for e-mail type '{0}' and culture '{1}'. Make sure that a template is configured for e-mail type {0} on profile {2}.", emailTypeName, localizationContext.CurrentCultureCode, profile.Name));
                }
                EmailProfileInformation profileInformation = profile.GetProfileInformation(content.EmailType);
                string contentId = content.ContentId;
                Uri relativeUri = new Uri(this.ContentService.GetContentUrl(contentId), UriKind.RelativeOrAbsolute);
                Uri uri = new Uri(HttpContext.Current.Request.Url, relativeUri);
                WebClient webClient = new WebClient();
                byte[] bytes = webClient.DownloadData(uri.AbsoluteUri + this.BuildQueryStringParameters(templateParameters)); // CRASHES HERE
                System.Text.UTF8Encoding uTF8Encoding = new System.Text.UTF8Encoding();

    System.Net.WebExceptionThe remote server returned an error: (404) Not Found.

    UCommerce.Pipelines.PipelineException: Exception occoured while processing pipeline 'UCommerce.Pipelines.Checkout.CheckoutPipeline'. See inner exception for details. ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
       at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
       at System.Net.WebClient.DownloadData(Uri address)
       at UCommerce.Transactions.EmailService.Send(ILocalizationContext localizationContext, EmailProfile profile, String emailTypeName, MailAddress to, IDictionary`2 templateParameters)
       at UCommerce.Pipelines.Common.SendEmailTask.Execute(PurchaseOrder purchaseOrder)
       at UCommerce.Pipelines.Pipeline`1.Execute(T subject)
       --- End of inner exception stack trace ---
       at UCommerce.Pipelines.Pipeline`1.Execute(T subject)
  • Wouter 49 posts 76 karma points
    Nov 27, 2013 @ 11:21
    Wouter
    0

    Some extra information. Since the e-mail templates reside outside the default HOME node, we've set the hostname on the parent folder of the e-mail templates: mysite.nl/email.

  • Jesper Nielsen 141 posts 498 karma points
    Dec 02, 2013 @ 09:57
    Jesper Nielsen
    0

    Hi Wouter,

    The hostname from the original request is used for getting the email content. So please make sure the hostname can be resolved correctly.

    A typical issue is that the internal DNS lookup fails for the hostname, then the request gets passed to "outside" the firewall. Then the request is not allowed back inside the firewall.

    One way of getting around it is to add the hostname to the hosts file, if you have control over the machine.

    Please note that content and email must be on the same hostname.

    Kind regards,

    Jesper

  • Wouter 49 posts 76 karma points
    Dec 02, 2013 @ 11:24
    Wouter
    0

    Hi, we are still looking in to this. I would advise uCommerce to re-think the way this works. I dont see why a webrequest is needed when the e-mail templates are on the same server: You can use IO to read the file on disk (e-mail template) and then replace the placeholders in that template with the appropiate content. For example:

            /// <summary>
            /// Get html template
            /// </summary>
            /// <param name="template"></param>
            /// <returns></returns>
            public static string GetTemplate(Template template, Dictionary<string, string> arguments)
            {
                var templateContent = String.Empty;
                var fileName = StringValueAttribute.GetStringValue(template);
    
                var key = "MySite.Library.Helpers.MailHelper:GetTemplate_" + fileName;
                if (CacheHelper.Exists(key)) {
                    templateContent = CacheHelper.Get<string>(key);
                }
                else {
                    var templatePath = HttpContext.Current.Server.MapPath(
                        ConfigurationManager.AppSettings["Site.Email.TemplatePath"]);
    
                    if (System.IO.Directory.Exists(templatePath)) {
                        if (!templatePath.EndsWith("\\")) {
                            templatePath += "\\";
                        }
                        templatePath += fileName;
    
                        // read template contents
                        if (System.IO.File.Exists(templatePath)) {
                            try {
                                templateContent = System.IO.File.ReadAllText(templatePath);
                                if (!String.IsNullOrEmpty(templateContent)) {
                                    foreach (var argument in arguments) {
                                        templateContent = templateContent.Replace(argument.Key, argument.Value);
                                    }
                                }
                                CacheHelper.Add(templateContent, key);
                            } catch (Exception ex) {
                                ExceptionHelper.LogException(ex);
                            }
                        }
                    }
                }
    
                return templateContent;
            }
Please Sign in or register to post replies

Write your reply to:

Draft