예제 #1
0
        public void DNN_12430_IsHtml_RegExTimeout()
        {
            var result =
                HtmlUtils.IsHtml(
                    @"'New Event: <a href=\""http://localhost/dnn540/Home/tabid/40/ModuleID/389/ItemID/8/mctl/EventDetails/Default.aspx"">Test</a> on Saturday, May 08, 2010 2:00 AM to Saturday, May 08, 2010 2:30 AM  - One time event - has been added");

            Assert.IsTrue(result);
        }
예제 #2
0
        public static string SendEmail(string fromAddress, string senderAddress, string toAddress, string subject, string body, ICollection <MailAttachment> attachments)
        {
            var mailInfo = new MailInfo
            {
                From         = fromAddress,
                Sender       = senderAddress,
                To           = toAddress,
                Subject      = subject,
                Body         = body,
                Priority     = MailPriority.Normal,
                BodyFormat   = HtmlUtils.IsHtml(body) ? MailFormat.Html : MailFormat.Text,
                BodyEncoding = Encoding.UTF8,
                Attachments  = attachments,
            };

            return(MailProvider.Instance().SendMail(mailInfo));
        }
예제 #3
0
        public static string SendEmail(string fromAddress, string senderAddress, string toAddress, string subject, string body, List <Attachment> attachments)
        {
            if ((string.IsNullOrEmpty(Host.SMTPServer)))
            {
                return("SMTP Server not configured");
            }

            var emailMessage = new MailMessage(fromAddress, toAddress)
            {
                Sender = new MailAddress(senderAddress)
            };

            return(SendMailInternal(emailMessage, subject, body, MailPriority.Normal,
                                    HtmlUtils.IsHtml(body) ? MailFormat.Html : MailFormat.Text,
                                    Encoding.UTF8, attachments,
                                    Host.SMTPServer, Host.SMTPAuthentication, Host.SMTPUsername,
                                    Host.SMTPPassword, Host.EnableSMTPSSL));
        }
예제 #4
0
        public static void SendEmail(string fromAddress, string senderAddress, string toAddress, string subject, string body)
        {
            if (string.IsNullOrEmpty(Host.SMTPServer) || string.IsNullOrEmpty(fromAddress) || string.IsNullOrEmpty(senderAddress) || string.IsNullOrEmpty(toAddress))
            {
                return;
            }

            var emailMessage = new MailMessage(fromAddress, toAddress)
            {
                Sender = new MailAddress(senderAddress)
            };

            SendMailInternal(emailMessage, subject, body, MailPriority.Normal,
                             HtmlUtils.IsHtml(body) ? MailFormat.Html : MailFormat.Text,
                             Encoding.UTF8, new List <Attachment>(),
                             Host.SMTPServer, Host.SMTPAuthentication, Host.SMTPUsername,
                             Host.SMTPPassword, Host.EnableSMTPSSL);
        }
예제 #5
0
        public static void SendEmail(string fromAddress, string senderAddress, string toAddress, string subject, string body)
        {
            if (string.IsNullOrWhiteSpace(Host.SMTPServer) || string.IsNullOrEmpty(fromAddress) || string.IsNullOrEmpty(senderAddress) || string.IsNullOrEmpty(toAddress))
            {
                return;
            }

            var mailInfo = new MailInfo
            {
                From         = fromAddress,
                Sender       = senderAddress,
                To           = toAddress,
                Subject      = subject,
                Body         = body,
                Priority     = MailPriority.Normal,
                BodyFormat   = HtmlUtils.IsHtml(body) ? MailFormat.Html : MailFormat.Text,
                BodyEncoding = Encoding.UTF8,
            };

            MailProvider.Instance().SendMail(mailInfo);
        }
예제 #6
0
 public static bool IsHTMLMail(string Body)
 {
     return(HtmlUtils.IsHtml(Body));
 }
예제 #7
0
        public void DNN_12926_IsHtml_Detection()
        {
            var result = HtmlUtils.IsHtml("this is a test of dnnmail: <a href='http://www.dotnetnuke.com'>DotNetNuke</a>");

            Assert.IsTrue(result);
        }
예제 #8
0
        private void SendOrderStatusChangeEmail(OrderInfo order)
        {
            // Get Store Currency Symbol
            if (!string.IsNullOrEmpty(StoreSettings.CurrencySymbol))
            {
                order.CurrencySymbol = StoreSettings.CurrencySymbol;
            }

            // Get Order Date Format
            string orderDateFormat = Localization.GetString("OrderDateFormat", LocalResourceFile);

            if (!string.IsNullOrEmpty(orderDateFormat))
            {
                order.DateFormat = orderDateFormat;
            }

            // Get Customer Email
            string customerEmail = CheckoutControl.BillingAddress.Email;

            // Get Admin Email
            string adminEmail = StoreSettings.DefaultEmailAddress;

            // Customer Order Email Template
            string customerSubjectEmail = Localization.GetString("CustomerStatusChangedEmailSubject", LocalResourceFile);
            string customerBodyEmail    = Localization.GetString("CustomerStatusChangedEmailBody", LocalResourceFile);

            // Extract or remove IFPAID token
            Match regPaidMatch = RegPaid.Match(customerBodyEmail);

            if (regPaidMatch.Success)
            {
                // If Status is Paid
                if (order.OrderStatusID == 7)
                {
                    // Replace IFPAID token by his content
                    string paidTemplate = regPaidMatch.Groups[1].ToString();
                    paidTemplate      = RegStripStartNewLine.Replace(paidTemplate, string.Empty);
                    paidTemplate      = RegStripEndNewLine.Replace(paidTemplate, string.Empty);
                    customerBodyEmail = RegPaid.Replace(customerBodyEmail, paidTemplate);
                }
                else // Remove IFPAID token
                {
                    customerBodyEmail = RegPaid.Replace(customerBodyEmail, string.Empty);
                }
            }

            // Admin Order Email Template
            string adminSubjectEmail = Localization.GetString("AdminStatusChangedEmailSubject", LocalResourceFile);
            string adminBodyEmail    = Localization.GetString("AdminStatusChangedEmailBody", LocalResourceFile);

            // Init Email Order Replacement Tokens
            EmailOrderTokenReplace tkEmailOrder = new EmailOrderTokenReplace
            {
                StoreSettings = StoreSettings,
                Order         = order
            };

            // Replace tokens
            customerSubjectEmail = tkEmailOrder.ReplaceEmailOrderTokens(customerSubjectEmail);
            customerBodyEmail    = tkEmailOrder.ReplaceEmailOrderTokens(customerBodyEmail);
            adminSubjectEmail    = tkEmailOrder.ReplaceEmailOrderTokens(adminSubjectEmail);
            adminBodyEmail       = tkEmailOrder.ReplaceEmailOrderTokens(adminBodyEmail);

            try
            {
                // Send Customer Email
                string result = Mail.SendMail(adminEmail, customerEmail, "", customerSubjectEmail, customerBodyEmail, "", HtmlUtils.IsHtml(customerBodyEmail) ? MailFormat.Html.ToString() : MailFormat.Text.ToString(), "", "", "", "");
                if (!string.IsNullOrEmpty(result))
                {
                    LogSMTPError(customerEmail, result);
                }

                // Send Store Admin Email
                result = Mail.SendMail(adminEmail, adminEmail, "", adminSubjectEmail, adminBodyEmail, "", HtmlUtils.IsHtml(adminBodyEmail) ? MailFormat.Html.ToString() : MailFormat.Text.ToString(), "", "", "", "");
                if (!string.IsNullOrEmpty(result))
                {
                    LogSMTPError(customerEmail, result);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
예제 #9
0
        protected virtual void GenerateOrderConfirmation()
        {
            OrderInfo order = CheckoutControl.Order;

            if (order != null)
            {
                // Store admin
                string adminDetailTemplate = string.Empty;
                bool   adminDetail         = false;
                // Customer
                string customerDetailTemplate = string.Empty;
                bool   customerDetail         = false;

                IAddressInfo billingAddress  = CheckoutControl.BillingAddress;
                IAddressInfo shippingAddress = CheckoutControl.ShippingAddress;

                // Get Customer Email
                string customerEmail = billingAddress.Email;

                // Get Admin Email
                string adminEmail = StoreSettings.DefaultEmailAddress;

                // Get Store Currency Symbol
                if (!string.IsNullOrEmpty(StoreSettings.CurrencySymbol))
                {
                    order.CurrencySymbol = StoreSettings.CurrencySymbol;
                }

                // Get Order Date Format
                string orderDateFormat = Localization.GetString("OrderDateFormat", LocalResourceFile);
                if (string.IsNullOrEmpty(orderDateFormat) == false)
                {
                    order.DateFormat = orderDateFormat;
                }

                // Customer Order Email Template
                string customerSubjectEmail    = Localization.GetString("CustomerOrderEmailSubject", LocalResourceFile);
                string customerBodyEmail       = Localization.GetString("CustomerOrderEmailBody", LocalResourceFile);
                string customerAddressTemplate = Localization.GetString("CustomerAddressTemplate", LocalResourceFile);

                // Extract Detail Order from Customer EmailTemplate
                Match regCustomerMatch = RegDetails.Match(customerBodyEmail);
                if (regCustomerMatch.Success)
                {
                    customerDetail         = true;
                    customerDetailTemplate = regCustomerMatch.Groups[1].ToString();
                    customerDetailTemplate = RegStripStartNewLine.Replace(customerDetailTemplate, string.Empty);
                    customerDetailTemplate = RegStripEndNewLine.Replace(customerDetailTemplate, string.Empty);
                }

                // Extract or remove IFDISCOUNT token
                Match regCustomerDiscountMatch = RegDiscount.Match(customerBodyEmail);
                if (regCustomerDiscountMatch.Success)
                {
                    if (order.CouponID != Null.NullInteger && order.Discount != Null.NullDecimal)
                    {
                        // Replace IFDISCOUNT token by his content
                        string discountTemplate = regCustomerDiscountMatch.Groups[1].ToString();
                        discountTemplate  = RegStripStartNewLine.Replace(discountTemplate, string.Empty);
                        discountTemplate  = RegStripEndNewLine.Replace(discountTemplate, string.Empty);
                        customerBodyEmail = RegDiscount.Replace(customerBodyEmail, discountTemplate);
                    }
                    else // Remove IFDISCOUNT token
                    {
                        customerBodyEmail = RegDiscount.Replace(customerBodyEmail, string.Empty);
                    }
                }

                // Extract or remove IFSHIPPINGCOST token
                Match regShippingCostMatch = RegShippingCost.Match(customerBodyEmail);
                if (regShippingCostMatch.Success)
                {
                    if (order.ShippingCost > 0)
                    {
                        // Replace IFSHIPPINGCOST token by his content
                        string shippingCostTemplate = regShippingCostMatch.Groups[1].ToString();
                        shippingCostTemplate = RegStripStartNewLine.Replace(shippingCostTemplate, string.Empty);
                        shippingCostTemplate = RegStripEndNewLine.Replace(shippingCostTemplate, string.Empty);
                        customerBodyEmail    = RegShippingCost.Replace(customerBodyEmail, shippingCostTemplate);
                    }
                    else // Remove IFSHIPPINGCOST token
                    {
                        customerBodyEmail = RegShippingCost.Replace(customerBodyEmail, string.Empty);
                    }
                }

                // Replace BillingAddress token (if present) by the the formated Billing Address
                if (customerBodyEmail.IndexOf("[BillingAddress]", StringComparison.InvariantCultureIgnoreCase) != Null.NullInteger)
                {
                    customerBodyEmail = customerBodyEmail.Replace("[BillingAddress]", billingAddress.Format(customerAddressTemplate));
                }

                // Extract or remove Shipping Address Template from Customer Email Template
                if (shippingAddress.AddressID != Null.NullInteger)
                {
                    // Remove Pickup Template
                    customerBodyEmail = RegPickup.Replace(customerBodyEmail, string.Empty);
                    // Replace Shipping Address Template
                    Match regShippingMatch = RegShipping.Match(customerBodyEmail);
                    if (regShippingMatch.Success)
                    {
                        string shippingTemplate = regShippingMatch.Groups[1].ToString();
                        shippingTemplate  = RegStripStartNewLine.Replace(shippingTemplate, string.Empty);
                        shippingTemplate  = RegStripEndNewLine.Replace(shippingTemplate, string.Empty);
                        customerBodyEmail = RegShipping.Replace(customerBodyEmail, shippingTemplate);
                    }

                    // Replace ShippingAddress token (if present) by the the formated Shipping Address
                    if (customerBodyEmail.IndexOf("[ShippingAddress]", StringComparison.InvariantCultureIgnoreCase) != Null.NullInteger)
                    {
                        customerBodyEmail = customerBodyEmail.Replace("[ShippingAddress]", shippingAddress.Format(customerAddressTemplate));
                    }
                }
                else
                {
                    // Remove Shipping Address Template
                    customerBodyEmail = RegShipping.Replace(customerBodyEmail, string.Empty);
                    // Replace Pickup Template
                    Match regPickupMatch = RegPickup.Match(customerBodyEmail);
                    if (regPickupMatch.Success)
                    {
                        string pickupTemplate = regPickupMatch.Groups[1].ToString();
                        pickupTemplate    = RegStripStartNewLine.Replace(pickupTemplate, string.Empty);
                        pickupTemplate    = RegStripEndNewLine.Replace(pickupTemplate, string.Empty);
                        customerBodyEmail = RegPickup.Replace(customerBodyEmail, pickupTemplate);
                    }
                }

                // Admin Order Email Template
                string adminSubjectEmail = Localization.GetString("AdminOrderEmailSubject", LocalResourceFile);
                string adminBodyEmail    = Localization.GetString("AdminOrderEmailBody", LocalResourceFile);

                // Extract Detail Order from Admin EmailTemplate
                Match regAdminMatch = RegDetails.Match(adminBodyEmail);
                if (regAdminMatch.Success)
                {
                    adminDetail         = true;
                    adminDetailTemplate = regAdminMatch.Groups[1].ToString();
                    adminDetailTemplate = RegStripStartNewLine.Replace(adminDetailTemplate, string.Empty);
                    adminDetailTemplate = RegStripEndNewLine.Replace(adminDetailTemplate, string.Empty);
                }

                // Extract or remove IFDISCOUNT token
                Match regAdminDiscountMatch = RegDiscount.Match(adminBodyEmail);
                if (regAdminDiscountMatch.Success)
                {
                    if (order.CouponID != Null.NullInteger && order.Discount != Null.NullDecimal)
                    {
                        // Replace IFDISCOUNT token by his content
                        string discountTemplate = regAdminDiscountMatch.Groups[1].ToString();
                        discountTemplate = RegStripStartNewLine.Replace(discountTemplate, string.Empty);
                        discountTemplate = RegStripEndNewLine.Replace(discountTemplate, string.Empty);
                        adminBodyEmail   = RegDiscount.Replace(adminBodyEmail, discountTemplate);
                    }
                    else // Remove IFDISCOUNT token
                    {
                        adminBodyEmail = RegDiscount.Replace(adminBodyEmail, string.Empty);
                    }
                }

                // Extract or remove IFSHIPPINGCOST token
                Match regAdminShippingCostMatch = RegShippingCost.Match(adminBodyEmail);
                if (regAdminShippingCostMatch.Success)
                {
                    if (order.ShippingCost > 0)
                    {
                        // Replace IFSHIPPINGCOST token by his content
                        string shippingCostTemplate = regAdminShippingCostMatch.Groups[1].ToString();
                        shippingCostTemplate = RegStripStartNewLine.Replace(shippingCostTemplate, string.Empty);
                        shippingCostTemplate = RegStripEndNewLine.Replace(shippingCostTemplate, string.Empty);
                        adminBodyEmail       = RegShippingCost.Replace(adminBodyEmail, shippingCostTemplate);
                    }
                    else // Remove IFSHIPPINGCOST token
                    {
                        adminBodyEmail = RegShippingCost.Replace(adminBodyEmail, string.Empty);
                    }
                }

                // Replace BillingAddress token (if present) by the the formated Billing Address
                if (adminBodyEmail.IndexOf("[BillingAddress]", StringComparison.InvariantCultureIgnoreCase) != Null.NullInteger)
                {
                    adminBodyEmail = adminBodyEmail.Replace("[BillingAddress]", billingAddress.Format(customerAddressTemplate));
                }

                // Extract or remove Shipping Address Template from Admin Email Template
                if (shippingAddress.AddressID != Null.NullInteger)
                {
                    // Remove Pickup Template
                    adminBodyEmail = RegPickup.Replace(adminBodyEmail, string.Empty);
                    // Replace Shipping Address Template
                    Match regShippingMatch = RegShipping.Match(adminBodyEmail);
                    if (regShippingMatch.Success)
                    {
                        string shippingTemplate = regShippingMatch.Groups[1].ToString();
                        shippingTemplate = RegStripStartNewLine.Replace(shippingTemplate, string.Empty);
                        shippingTemplate = RegStripEndNewLine.Replace(shippingTemplate, string.Empty);
                        adminBodyEmail   = RegShipping.Replace(adminBodyEmail, shippingTemplate);
                    }

                    // Replace ShippingAddress token (if present) by the the formated Shipping Address
                    if (adminBodyEmail.IndexOf("[ShippingAddress]", StringComparison.InvariantCultureIgnoreCase) != Null.NullInteger)
                    {
                        adminBodyEmail = adminBodyEmail.Replace("[ShippingAddress]", shippingAddress.Format(customerAddressTemplate));
                    }
                }
                else
                {
                    // Remove Shipping Address Template
                    adminBodyEmail = RegShipping.Replace(adminBodyEmail, string.Empty);
                    // Replace Pickup Template
                    Match regPickupMatch = RegPickup.Match(adminBodyEmail);
                    if (regPickupMatch.Success)
                    {
                        string pickupTemplate = regPickupMatch.Groups[1].ToString();
                        pickupTemplate = RegStripStartNewLine.Replace(pickupTemplate, string.Empty);
                        pickupTemplate = RegStripEndNewLine.Replace(pickupTemplate, string.Empty);
                        adminBodyEmail = RegShipping.Replace(adminBodyEmail, pickupTemplate);
                    }
                }

                // Init Email Order Replacement Tokens
                EmailOrderTokenReplace tkEmailOrder = new EmailOrderTokenReplace
                {
                    StoreSettings   = StoreSettings,
                    Order           = order,
                    BillingAddress  = billingAddress,
                    ShippingAddress = shippingAddress
                };

                // Replace tokens
                customerSubjectEmail = tkEmailOrder.ReplaceEmailOrderTokens(customerSubjectEmail);
                customerBodyEmail    = tkEmailOrder.ReplaceEmailOrderTokens(customerBodyEmail);
                adminSubjectEmail    = tkEmailOrder.ReplaceEmailOrderTokens(adminSubjectEmail);
                adminBodyEmail       = tkEmailOrder.ReplaceEmailOrderTokens(adminBodyEmail);

                // Order Details Template
                if (customerDetail || adminDetail)
                {
                    // Get Order Details
                    OrderController        orderController = new OrderController();
                    List <OrderDetailInfo> orderDetails    = orderController.GetOrderDetails(order.OrderID);
                    if (orderDetails != null)
                    {
                        // Update Stock Products if needed
                        if (StoreSettings.InventoryManagement)
                        {
                            DecreaseStock(orderDetails);
                        }

                        // Replace Order Detail Tokens
                        StringBuilder           customerDetailText = new StringBuilder();
                        StringBuilder           adminDetailText    = new StringBuilder();
                        OrderDetailTokenReplace tkOrderDetail      = new OrderDetailTokenReplace();

                        foreach (OrderDetailInfo detail in orderDetails)
                        {
                            tkOrderDetail.OrderDetail = detail;
                            if (customerDetail)
                            {
                                customerDetailText.AppendLine(tkOrderDetail.ReplaceOrderDetailTokens(customerDetailTemplate));
                            }
                            if (adminDetail)
                            {
                                adminDetailText.AppendLine(tkOrderDetail.ReplaceOrderDetailTokens(adminDetailTemplate));
                            }
                        }
                        if (customerDetail)
                        {
                            customerBodyEmail = RegDetails.Replace(customerBodyEmail, RegStripEndNewLine.Replace(customerDetailText.ToString(), string.Empty));
                        }
                        if (adminDetail)
                        {
                            adminBodyEmail = RegDetails.Replace(customerBodyEmail, RegStripEndNewLine.Replace(adminDetailText.ToString(), string.Empty));
                        }
                    }
                }

                try
                {
                    // Send Customer Email
                    string result = Mail.SendMail(adminEmail, customerEmail, "", customerSubjectEmail, customerBodyEmail, "", HtmlUtils.IsHtml(customerBodyEmail) ? MailFormat.Html.ToString() : MailFormat.Text.ToString(), "", "", "", "");
                    if (!string.IsNullOrEmpty(result))
                    {
                        LogSMTPError(customerEmail, result);
                    }

                    // Send Store Admin Email
                    result = Mail.SendMail(adminEmail, adminEmail, "", adminSubjectEmail, adminBodyEmail, "", HtmlUtils.IsHtml(adminBodyEmail) ? MailFormat.Html.ToString() : MailFormat.Text.ToString(), "", "", "", "");
                    if (!string.IsNullOrEmpty(result))
                    {
                        LogSMTPError(customerEmail, result);
                    }
                }
                catch (Exception ex)
                {
                    Exceptions.ProcessModuleLoadException(this, ex);
                }
            }
        }
예제 #10
0
        public void DNN_12926_IsHtml_Detection()
        {
            var result = HtmlUtils.IsHtml("this is a test of hccmail: <a href='https://hotcakes.org'>Hotcakes Commerce</a>");

            Assert.IsTrue(result);
        }
예제 #11
0
        private void SendOrderStatusChangeEmail(OrderInfo order)
        {
            // Get Store Currency Symbol
            if (!string.IsNullOrEmpty(StoreSettings.CurrencySymbol))
            {
                order.CurrencySymbol = StoreSettings.CurrencySymbol;
            }

            // Get Order Date Format
            string orderDateFormat = Localization.GetString("OrderDateFormat", LocalResourceFile);

            if (!string.IsNullOrEmpty(orderDateFormat))
            {
                order.DateFormat = orderDateFormat;
            }

            // Get Customer Email
            IAddressInfo billingAddress = GetAddress(order.BillingAddressID, order.CustomerID);
            string       customerEmail  = billingAddress.Email;

            // Try to get email address from user account,
            // this could be required for older orders.
            if (string.IsNullOrEmpty(customerEmail))
            {
                UserController userControler = new UserController();
                UserInfo       user          = userControler.GetUser(PortalId, order.CustomerID);
                customerEmail = user.Email;
            }

            // Get Admin Email
            string adminEmail = StoreSettings.DefaultEmailAddress;

            // Customer Order Email Template
            string customerSubjectEmail = Localization.GetString("CustomerStatusChangedEmailSubject", LocalResourceFile);
            string customerBodyEmail    = Localization.GetString("CustomerStatusChangedEmailBody", LocalResourceFile);

            // Extract or remove IFPAID token
            Match regPaidMatch = RegPaid.Match(customerBodyEmail);

            if (regPaidMatch.Success)
            {
                // If Status is Paid
                if (order.OrderStatusID == 7)
                {
                    // Replace IFPAID token by his content
                    string shippingCostTemplate = regPaidMatch.Groups[1].ToString();
                    shippingCostTemplate = RegStripStartNewLine.Replace(shippingCostTemplate, string.Empty);
                    shippingCostTemplate = RegStripEndNewLine.Replace(shippingCostTemplate, string.Empty);
                    customerBodyEmail    = RegPaid.Replace(customerBodyEmail, shippingCostTemplate);
                }
                else // Remove IFPAID token
                {
                    customerBodyEmail = RegPaid.Replace(customerBodyEmail, string.Empty);
                }
            }

            // Admin Order Email Template
            string adminSubjectEmail = Localization.GetString("AdminStatusChangedEmailSubject", LocalResourceFile);
            string adminBodyEmail    = Localization.GetString("AdminStatusChangedEmailBody", LocalResourceFile);

            // Init Email Order Replacement Tokens
            EmailOrderTokenReplace tkEmailOrder = new EmailOrderTokenReplace
            {
                StoreSettings = StoreSettings,
                Order         = order
            };

            // Replace tokens
            customerSubjectEmail = tkEmailOrder.ReplaceEmailOrderTokens(customerSubjectEmail);
            customerBodyEmail    = tkEmailOrder.ReplaceEmailOrderTokens(customerBodyEmail);
            adminSubjectEmail    = tkEmailOrder.ReplaceEmailOrderTokens(adminSubjectEmail);
            adminBodyEmail       = tkEmailOrder.ReplaceEmailOrderTokens(adminBodyEmail);

            try
            {
                // Send Customer Email
                Mail.SendMail(adminEmail, customerEmail, "", customerSubjectEmail, customerBodyEmail, "", HtmlUtils.IsHtml(customerBodyEmail) ? MailFormat.Html.ToString() : MailFormat.Text.ToString(), "", "", "", "");

                // Send Store Admin Email
                Mail.SendMail(adminEmail, adminEmail, "", adminSubjectEmail, adminBodyEmail, "", HtmlUtils.IsHtml(adminBodyEmail) ? MailFormat.Html.ToString() : MailFormat.Text.ToString(), "", "", "", "");
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
예제 #12
0
        public static string SendEmail(string fromAddress, string senderAddress, string toAddress, string subject, string body, List <Attachment> Attachments)
        {
            if ((string.IsNullOrEmpty(Host.SMTPServer)))
            {
                return("SMTP Server not configured");
            }

            System.Net.Mail.MailMessage emailMessage = new System.Net.Mail.MailMessage(fromAddress, toAddress, subject, body);
            emailMessage.Sender = new MailAddress(senderAddress);

            if ((HtmlUtils.IsHtml(body)))
            {
                emailMessage.IsBodyHtml = true;
            }

            foreach (Attachment myAtt in Attachments)
            {
                emailMessage.Attachments.Add(myAtt);
            }

            System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(Host.SMTPServer);

            string[] smtpHostParts = Host.SMTPServer.Split(':');
            if (smtpHostParts.Length > 1)
            {
                smtpClient.Host = smtpHostParts[0];
                smtpClient.Port = Convert.ToInt32(smtpHostParts[1]);
            }


            switch (Host.SMTPAuthentication)
            {
            case "":
            case "0":
                // anonymous
                break;

            case "1":
                // basic
                if (!string.IsNullOrEmpty(Host.SMTPUsername) & !string.IsNullOrEmpty(Host.SMTPPassword))
                {
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials           = new System.Net.NetworkCredential(Host.SMTPUsername, Host.SMTPPassword);
                }
                break;

            case "2":
                // NTLM
                smtpClient.UseDefaultCredentials = true;
                break;
            }

            smtpClient.EnableSsl = Host.EnableSMTPSSL;

            //'Retry up to 5 times to send the message
            for (int index = 1; index <= 5; index++)
            {
                try
                {
                    smtpClient.Send(emailMessage);
                    return("");
                }
                catch (Exception ex)
                {
                    if ((index == 5))
                    {
                        ex.ToString();
                    }
                    Thread.Sleep(1000);
                }
            }

            return("");
        }
예제 #13
0
        public static string SendMail(string MailFrom, string MailTo, string Cc, string Bcc, string ReplyTo, MailPriority Priority, string Subject, MailFormat BodyFormat, System.Text.Encoding BodyEncoding, string Body,
                                      List <Attachment> Attachments, string SMTPServer, string SMTPAuthentication, string SMTPUsername, string SMTPPassword, bool SMTPEnableSSL)
        {
            string retValue = "";

            if (!IsValidEmailAddress(MailFrom, PortalSettings.Current != null ? PortalSettings.Current.PortalId : Null.NullInteger))
            {
                ArgumentException ex = new ArgumentException(string.Format(Localization.Localization.GetString("EXCEPTION_InvalidEmailAddress", PortalSettings.Current), MailFrom));
                Exceptions.Exceptions.LogException(ex);
                return(ex.Message);
            }

            if (string.IsNullOrEmpty(SMTPServer) && !string.IsNullOrEmpty(Host.SMTPServer))
            {
                SMTPServer = Host.SMTPServer;
            }
            if (string.IsNullOrEmpty(SMTPAuthentication) && !string.IsNullOrEmpty(Host.SMTPAuthentication))
            {
                SMTPAuthentication = Host.SMTPAuthentication;
            }
            if (string.IsNullOrEmpty(SMTPUsername) && !string.IsNullOrEmpty(Host.SMTPUsername))
            {
                SMTPUsername = Host.SMTPUsername;
            }
            if (string.IsNullOrEmpty(SMTPPassword) && !string.IsNullOrEmpty(Host.SMTPPassword))
            {
                SMTPPassword = Host.SMTPPassword;
            }
            MailTo = MailTo.Replace(";", ",");
            Cc     = Cc.Replace(";", ",");
            Bcc    = Bcc.Replace(";", ",");
            System.Net.Mail.MailMessage objMail = null;
            try
            {
                objMail      = new System.Net.Mail.MailMessage();
                objMail.From = new MailAddress(MailFrom);
                if (!String.IsNullOrEmpty(MailTo))
                {
                    objMail.To.Add(MailTo);
                }
                if (!String.IsNullOrEmpty(Cc))
                {
                    objMail.CC.Add(Cc);
                }
                if (!String.IsNullOrEmpty(Bcc))
                {
                    objMail.Bcc.Add(Bcc);
                }
                if (ReplyTo != string.Empty)
                {
                    objMail.ReplyTo = new System.Net.Mail.MailAddress(ReplyTo);
                }
                objMail.Priority   = (System.Net.Mail.MailPriority)Priority;
                objMail.IsBodyHtml = BodyFormat == MailFormat.Html;
                foreach (Attachment myAtt in Attachments)
                {
                    objMail.Attachments.Add(myAtt);
                }
                objMail.SubjectEncoding = BodyEncoding;
                objMail.Subject         = HtmlUtils.StripWhiteSpace(Subject, true);
                objMail.BodyEncoding    = BodyEncoding;
                System.Net.Mail.AlternateView PlainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(ConvertToText(Body), null, "text/plain");
                objMail.AlternateViews.Add(PlainView);
                if (HtmlUtils.IsHtml(Body))
                {
                    System.Net.Mail.AlternateView HTMLView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
                    objMail.AlternateViews.Add(HTMLView);
                }
            }
            catch (Exception objException)
            {
                retValue = MailTo + ": " + objException.Message;
                Exceptions.Exceptions.LogException(objException);
            }
            if (objMail != null)
            {
                int SmtpPort = Null.NullInteger;
                int portPos  = SMTPServer.IndexOf(":");
                if (portPos > -1)
                {
                    SmtpPort   = Int32.Parse(SMTPServer.Substring(portPos + 1, SMTPServer.Length - portPos - 1));
                    SMTPServer = SMTPServer.Substring(0, portPos);
                }
                System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
                try
                {
                    if (!String.IsNullOrEmpty(SMTPServer))
                    {
                        smtpClient.Host = SMTPServer;
                        if (SmtpPort > Null.NullInteger)
                        {
                            smtpClient.Port = SmtpPort;
                        }
                        switch (SMTPAuthentication)
                        {
                        case "":
                        case "0":
                            break;

                        case "1":
                            if (!String.IsNullOrEmpty(SMTPUsername) && !String.IsNullOrEmpty(SMTPPassword))
                            {
                                smtpClient.UseDefaultCredentials = false;
                                smtpClient.Credentials           = new System.Net.NetworkCredential(SMTPUsername, SMTPPassword);
                            }
                            break;

                        case "2":
                            smtpClient.UseDefaultCredentials = true;
                            break;
                        }
                    }
                    smtpClient.EnableSsl = SMTPEnableSSL;
                    smtpClient.Send(objMail);
                    retValue = "";
                }
                catch (SmtpFailedRecipientException exc)
                {
                    retValue = string.Format(Localization.Localization.GetString("FailedRecipient"), exc.FailedRecipient);
                    Exceptions.Exceptions.LogException(exc);
                }
                catch (SmtpException exc)
                {
                    retValue = Localization.Localization.GetString("SMTPConfigurationProblem");
                    Exceptions.Exceptions.LogException(exc);
                }
                catch (Exception objException)
                {
                    if (objException.InnerException != null)
                    {
                        retValue = string.Concat(objException.Message, Environment.NewLine, objException.InnerException.Message);
                        Exceptions.Exceptions.LogException(objException.InnerException);
                    }
                    else
                    {
                        retValue = objException.Message;
                        Exceptions.Exceptions.LogException(objException);
                    }
                }
                finally
                {
                    objMail.Dispose();
                }
            }
            return(retValue);
        }