Copied to clipboard

Flag this post as spam?

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


  • deeppatel 25 posts 95 karma points
    Aug 09, 2017 @ 10:42
    deeppatel
    0

    Order Confirmation Email not working with ucommerce

    i have create one class file for send email

    public class NewSendEmailTask : IPipelineTask<PurchaseOrder>
        {
            private IEmailService EmailService { get; set; }
    
            private CommerceConfigurationProvider CommerceConfiguration { get; set; }
    
            private string EmailTypeName { get; set; }
    
            private ILoggingService LoggingService { get; set; }
    
            public NewSendEmailTask(string emailTypeName, ILoggingService loggingService, IEmailService emailService, CommerceConfigurationProvider commerceConfiguration)
            {
                this.EmailTypeName = emailTypeName;
                this.LoggingService = loggingService;
                this.EmailService = emailService;
                this.CommerceConfiguration = commerceConfiguration;
            }
    
            /// <summary>
            /// SendEmailTask Execute
            /// </summary>
            /// <param name="purchaseOrder"></param>
            /// <returns></returns>
            public PipelineExecutionResult Execute(PurchaseOrder purchaseOrder)
            {
                OrderAddress billingAddress = purchaseOrder.GetBillingAddress();
                if (billingAddress == (OrderAddress)null || string.IsNullOrEmpty(billingAddress.EmailAddress))
                {
                    return PipelineExecutionResult.Warning;
                }
                if (purchaseOrder.Discounts.Where(x => x.CampaignItemName == "B2B").Any() && (EmailTypeName == "OrderConfirmation"))
                {
                    return PipelineExecutionResult.Success;
                }; // If B2B order and mail is OrderConfirmation: mail does not have to be send, so do nothing and return Success
                CustomGlobalization customGlobalization = new CustomGlobalization(this.CommerceConfiguration);
                customGlobalization.SetCulture(new CultureInfo(purchaseOrder.CultureCode ?? customGlobalization.DefaultCulture.ToString()));
                try
                {
       this.EmailService.Send((ILocalizationContext)customGlobalization, purchaseOrder.ProductCatalogGroup.EmailProfile, this.EmailTypeName, new MailAddress(billingAddress.EmailAddress), (IDictionary<string, string>)new Dictionary<string, string>()
                    {
                      {
                        "orderNumber",
                        purchaseOrder.OrderNumber
                      },
                      {
                        "orderGuid",
                        purchaseOrder.OrderGuid.ToString()
                      }
                    });
    
                }
                catch (SmtpException ex)
                {
                    this.LoggingService.Log<NewSendEmailTask>((Exception)ex);
                }
                return PipelineExecutionResult.Success;
            }
        }
    

    after this i have create configuration file for register method

    <configuration>
      <components>
        <component
             id="Checkout.NewSendEmailTask"
               service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce"
                   type="ld.Businesslogic.Pipelines.Checkout.NewSendEmail.NewSendEmailTask, ld">
          <parameters>
            <EmailTypeName>OrderConfirmation</EmailTypeName>
          </parameters>
        </component>
      </components>
      <components>
        <partial-component id="Checkout">
          <parameters>
            <tasks>
              <array>
                <value insert-before="${Checkout.SendConfirmationEmail}">${Checkout.NewSendEmailTask}</value>
                <value remove="${Checkout.SendConfirmationEmail}" />
              </array>
            </tasks>
          </parameters>
        </partial-component>
      </components>
    </configuration>
    

    and also set sendgrid credentials in web.config file

    <mailSettings>
          <smtp from="from email address" deliveryMethod="Network">
            <network
                    defaultCredentials="false"
                    host="smtp.sendgrid.net"
                    port="587"
                    password="sendgrid account password"
                    userName="sendgrid account username/>
          </smtp>
    </mailSettings>
    

    my site hosted in aws server

    so any one know how to send email after order completed.

  • David Kelemen 8 posts 99 karma points
    Aug 11, 2017 @ 13:50
    David Kelemen
    0

    Hello,

    The code seems at first glance to be correct and so does the configuration, but it's unclear what breaks/does not work in your case.

    Are you encountering an error while the code executes? Could you debug your code, and make sure it is executed correctly, and if there's an error reply back with a stack trace so we have a lead to follow?

    Kind regards, David

  • deeppatel 25 posts 95 karma points
    Aug 12, 2017 @ 05:29
    deeppatel
    0

    Hello Devid

    Thanks for the reply.yes i debug my code and it's execute successfully with out any error. i have write log file also but not write any exception in my log file.

    when i set simple smtp configuration then i get "Unable to connect to the remote server" error but with sendgrid i didn't get any error like connection.it execute successfully with sendgrid.

    Thanks.

  • David Kelemen 8 posts 99 karma points
    Aug 14, 2017 @ 14:05
    David Kelemen
    0

    Hello,

    That seems to be a problem with the SMTP server configuration. A few things I can think of are either a firewall being configured to block the port your simple smtp configuration is using or the port being used by some other service.

    Make sure the port is free to be used for your e-mail server, or you could try configuring a different port for your SMTP.

    Regards, David

  • deeppatel 25 posts 95 karma points
    Aug 22, 2017 @ 04:21
    deeppatel
    0

    Thanks David, i will try to change smtp configuration and check what happen after change configuration.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft