private bool SendEmail(OrderTaskContext context, VendorManufacturer vendorOrManufacturer, Order order)
        {
            var storeSettingsProvider = Factory.CreateStoreSettingsProvider();
            var defaultCulture        = storeSettingsProvider.GetDefaultLocale();
            var hccRequestContext     = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, defaultCulture);
            var contentService        = Factory.CreateService <ContentService>(hccRequestContext);

            var toEmail = vendorOrManufacturer.EmailAddress;

            HtmlTemplate t            = null;
            var          templateBvin = vendorOrManufacturer.DropShipEmailTemplateId;

            if (templateBvin != string.Empty)
            {
                long templateId = 0;
                long.TryParse(templateBvin, out templateId);
                t = contentService.HtmlTemplates.Find(templateId);
            }
            if (t == null)
            {
                t = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.DropShippingNotice);
            }

            if (!string.IsNullOrEmpty(toEmail))
            {
                var replacers = new List <IReplaceable>();
                replacers.Add(order);
                replacers.Add(vendorOrManufacturer);
                t = t.ReplaceTagsInTemplate(hccRequestContext, replacers, order.ItemsAsReplaceable());

                var m = t.ConvertToMailMessage(toEmail);
                return(MailServices.SendMail(m, hccRequestContext.CurrentStore));
            }
            return(false);
        }
示例#2
0
        public override bool Execute(OrderTaskContext context)
        {
            CustomerAccount u = context.MTApp.MembershipServices.Customers.FindByEmail(context.Order.UserEmail);

            if (u != null)
            {
                if (u.Bvin != string.Empty)
                {
                    return(true);
                }
            }

            CustomerAccount n = new CustomerAccount();

            n.Email = context.Order.UserEmail;
            int length = WebAppSettings.PasswordMinimumLength;

            if (length < 8)
            {
                length = 8;
            }
            string newPassword = MerchantTribe.Web.PasswordGenerator.GeneratePassword(length);

            n.Password  = newPassword;
            n.FirstName = context.Order.ShippingAddress.FirstName;
            n.LastName  = context.Order.ShippingAddress.LastName;

            if (context.MTApp.MembershipServices.CreateCustomer(n, n.Password))
            {
                // Update Addresses for Customer
                context.Order.BillingAddress.CopyTo(n.BillingAddress);
                context.Order.ShippingAddress.CopyTo(n.ShippingAddress);
                context.MTApp.MembershipServices.UpdateCustomer(n);
                context.Order.CustomProperties.Add("bvsoftware", "allowpasswordreset", "1");

                // Email Password to Customer
                HtmlTemplate t = context.MTApp.ContentServices.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword);
                if (t != null)
                {
                    System.Net.Mail.MailMessage m;

                    List <IReplaceable> replacers = new List <IReplaceable>();
                    replacers.Add(n);
                    replacers.Add(new Replaceable("[[NewPassword]]", newPassword));
                    t = t.ReplaceTagsInTemplate(context.MTApp, replacers);

                    m = t.ConvertToMailMessage(n.Email);

                    if (MailServices.SendMail(m, context.MTApp.CurrentStore) == false)
                    {
                        EventLog.LogEvent("Create Account During Checkout", "Failed to send email to new customer " + n.Email, EventLogSeverity.Warning);
                    }
                }
            }
            context.UserId = n.Bvin;

            return(true);
        }
示例#3
0
        protected void btnSendStatusEmail_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            this.MessageBox1.ClearMessage();
            Order o = MTApp.OrderServices.Orders.FindForCurrentStore(this.BvinField.Value);

            if (o != null)
            {
                if (o.bvin != string.Empty)
                {
                    long templateId = 0;
                    long.TryParse(this.lstEmailTemplate.SelectedValue, out templateId);
                    HtmlTemplate t = MTApp.ContentServices.HtmlTemplates.Find(templateId);

                    if (t == null)
                    {
                        return;
                    }

                    string toEmail = o.UserEmail;

                    if (t.TemplateType == HtmlTemplateType.NewOrderForAdmin ||
                        t.TemplateType == HtmlTemplateType.DropShippingNotice ||
                        t.TemplateType == HtmlTemplateType.ContactFormToAdmin)
                    {
                        toEmail = MTApp.CurrentStore.Settings.MailServer.EmailForNewOrder;
                    }


                    if (toEmail.Trim().Length > 0)
                    {
                        System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
                        t = t.ReplaceTagsInTemplate(MTApp, o, o.ItemsAsReplaceable());
                        m = t.ConvertToMailMessage(toEmail);
                        if (m != null)
                        {
                            if (MerchantTribe.Commerce.Utilities.MailServices.SendMail(m, MTApp.CurrentStore))
                            {
                                this.MessageBox1.ShowOk("Email Sent!");
                            }
                            else
                            {
                                this.MessageBox1.ShowError("Message Send Failed.");
                            }
                        }
                        else
                        {
                            this.MessageBox1.ShowError("Message was sent successfully.");
                        }
                    }
                }
            }
            LoadOrder();
        }
示例#4
0
        public override bool Execute(OrderTaskContext context)
        {
            string       toEmail  = null;
            HtmlTemplate template = null;

            var culture = "en-US";

            switch (_emailTo)
            {
            case "Admin":
                toEmail = context.HccApp.CurrentStore.Settings.MailServer.EmailForNewOrder;
                var storeSettingsProvider = Factory.CreateStoreSettingsProvider();
                culture = storeSettingsProvider.GetDefaultLocale();
                break;

            case "Customer":
                toEmail = context.Order.UserEmail;
                culture = context.Order.UsedCulture;
                break;
            }

            var hccRequestContext = HccRequestContextUtils.GetContextWithCulture(context.RequestContext, culture);
            var contentService    = Factory.CreateService <ContentService>(hccRequestContext);

            switch (_emailTo)
            {
            case "Admin":
                template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.NewOrderForAdmin);
                break;

            case "Customer":
                template = contentService.GetHtmlTemplateOrDefault(HtmlTemplateType.NewOrder);
                break;
            }

            try
            {
                if (!string.IsNullOrEmpty(toEmail))
                {
                    template = template.ReplaceTagsInTemplateForOrder(hccRequestContext, context.Order);

                    var m = template.ConvertToMailMessage(toEmail);
                    MailServices.SendMail(m, hccRequestContext.CurrentStore);
                }
            }
            catch (Exception ex)
            {
                EventLog.LogEvent(ex);
            }

            return(true);
        }
示例#5
0
        private void SendReminder(string email)
        {
            if (!MerchantTribe.Web.Validation.EmailValidation.MeetsEmailFormatRequirements(email))
            {
                FlashWarning("Please enter a valid email address");
                return;
            }

            try
            {
                CustomerAccount thisUser    = MTApp.MembershipServices.Customers.FindByEmail(email);
                string          newPassword = string.Empty;

                if ((thisUser != null) && (thisUser.Bvin != string.Empty))
                {
                    newPassword       = MTApp.MembershipServices.GeneratePasswordForCustomer(WebAppSettings.PasswordMinimumLength + 2);
                    thisUser.Password = thisUser.EncryptPassword(newPassword);
                    if (MTApp.MembershipServices.UpdateCustomer(thisUser))
                    {
                        HtmlTemplate t = MTApp.ContentServices.GetHtmlTemplateOrDefault(HtmlTemplateType.ForgotPassword);
                        if (t != null)
                        {
                            System.Net.Mail.MailMessage m;
                            List <IReplaceable>         tempList = new List <IReplaceable>();
                            tempList.Add(thisUser);
                            tempList.Add(new Replaceable("[[NewPassword]]", newPassword));

                            t = t.ReplaceTagsInTemplate(MTApp, tempList);

                            m = t.ConvertToMailMessage(thisUser.Email);

                            if (MailServices.SendMail(m) == false)
                            {
                                FlashFailure("Error while sending mail!");
                            }
                        }

                        FlashSuccess("Your new password has been sent by email.");
                    }
                    else
                    {
                        FlashFailure("An error occurred while trying to update password.");
                    }
                }
                else
                {
                    FlashFailure(SiteTerms.GetTerm(SiteTermIds.Username) + " not found.");
                }
            }


            catch (SystemMembershipUserException CreateEx)
            {
                switch (CreateEx.Status)
                {
                case CreateUserStatus.UpdateFailed:
                    FlashFailure("Update to user account failed.");
                    break;

                default:
                    FlashFailure(CreateEx.Message);
                    break;
                }
            }
        }