Esempio n. 1
0
        public void TestLongSubjectEncoded()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddCcAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddBccAddress(TestAddressHelper.GetToAddress());
            emailmessage.Subject        = "Join our Group's Fundraising Efforts é test test test Gulf Little League";
            emailmessage.HeaderEncoding = DotNetOpenMail.Encoding.EncodingType.QuotedPrintable;
            emailmessage.XMailer        = "NUnit Test Mailer";
            emailmessage.TextPart       = new TextAttachment("This\r\nis the\r\ntext\r\npart.");
            emailmessage.HtmlPart       = new HtmlAttachment("<html><body>This<br>\r\nis the<br>\r\n<strong>HTML</strong><br>\r\npart.</body></html>");

            String content = emailmessage.ToDataString();

            emailmessage.Send(_smtpserver);
        }
Esempio n. 2
0
        public void TestExtraHeader()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddCcAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddBccAddress(TestAddressHelper.GetToAddress());
            emailmessage.Subject        = "Extra Header";
            emailmessage.HeaderEncoding = DotNetOpenMail.Encoding.EncodingType.QuotedPrintable;
            emailmessage.XMailer        = "NUnit Test Mailer";
            emailmessage.AddCustomHeader("MyHeader", "Value");
            emailmessage.TextPart = new TextAttachment("This\r\nis the\r\ntext\r\npart.");
            emailmessage.HtmlPart = new HtmlAttachment("<html><body>This<br>\r\nis the<br>\r\n<strong>HTML</strong><br>\r\npart.</body></html>");

            String content = emailmessage.ToDataString();

            emailmessage.Send(_smtpserver);
        }
Esempio n. 3
0
        public void TestHeaders()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddCcAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddCcAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddBccAddress(TestAddressHelper.GetToAddress());
            emailmessage.AddBccAddress(TestAddressHelper.GetToAddress());
            emailmessage.Subject  = "Test Headers";
            emailmessage.XMailer  = "NUnit Test Mailer";
            emailmessage.TextPart = new TextAttachment("This\r\nis the\r\ntext\r\npart.");
            emailmessage.HtmlPart = new HtmlAttachment("<html><body>This<br>\r\nis the<br>\r\n<strong>HTML</strong><br>\r\npart.</body></html>");

            String       content = emailmessage.ToDataString();
            StringReader sr      = new StringReader(content);

            int    i                = 0;
            String line             = null;
            bool   hasToHeader      = false;
            bool   hasFromHeader    = false;
            bool   hasSubjectHeader = false;
            bool   hasBccHeader     = false;
            bool   hasCcHeader      = false;
            bool   hasXMailerHeader = false;

            String expectedToAddress = TestAddressHelper.GetToAddress().Name + " <" + TestAddressHelper.GetToAddress().Email + ">";


            while ((line = sr.ReadLine()) != null)
            {
                i++;
                if (line.IndexOf("To: " + expectedToAddress + ", " + expectedToAddress) == 0)
                {
                    hasToHeader = true;
                }
                if (line.IndexOf("Cc: " + expectedToAddress + ", " + expectedToAddress) == 0)
                {
                    hasCcHeader = true;
                }
                if (line.IndexOf("Bcc: " + expectedToAddress + ", " + expectedToAddress) == 0)
                {
                    hasBccHeader = true;
                }

                if (line.IndexOf("From: " + emailmessage.FromAddress.ToString()) == 0)
                {
                    hasFromHeader = true;
                }
                if (line.IndexOf("Subject: " + emailmessage.Subject) == 0)
                {
                    hasSubjectHeader = true;
                }
                if (line.IndexOf("X-Mailer: NUnit Test Mailer") == 0)
                {
                    hasXMailerHeader = true;
                }
            }
            Assert.IsTrue(hasToHeader, "Missing TO Header");
            Assert.IsTrue(hasFromHeader, "Missing FROM Header");
            Assert.IsTrue(hasSubjectHeader, "Missing Subject Header");
            Assert.IsTrue(hasCcHeader, "Missing Cc Header");
            Assert.IsFalse(hasBccHeader, "Bcc Header Shouldn't appear");
            Assert.IsTrue(hasXMailerHeader, "Missing XMailer Header");
            //emailmessage.Send(_smtpserver);
        }
Esempio n. 4
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;


            #region getOrderInfo and Check

            TOrderNu _tOrder = new TOrderNu();
            _result = _tOrder.getOrderById(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _tOrder = _result.Object as TOrderNu;


            if (_tOrder.OrderId == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exits";

                return(_result);
            }

            TOrderNu _emailAddress = new TOrderNu();
            _result = _emailAddress.getMailAddress(_tOrder.CustomerId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _emailAddress = _result.Object as TOrderNu;



            TOrder_Line_ItemNu _tOrdersDetail = new TOrder_Line_ItemNu();
            _result = _tOrdersDetail.getOrdersDetail(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            EntityList _orderDetails = _result.ObjectList;


            if (_orderDetails.Count == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exits";

                return(_result);
            }


            #endregion

            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                if (_emailAddress.MailBCC.IndexOf(";") > 0)
                {
                    _emailAddress.MailBCC = _emailAddress.MailBCC.Remove(_emailAddress.MailBCC.Length - 1, 1);
                }

                if (_emailAddress.MailCC.IndexOf(";") > 0)
                {
                    _emailAddress.MailCC = _emailAddress.MailCC.Remove(_emailAddress.MailCC.Length - 1, 1);
                }

                if (_emailAddress.MailTo.IndexOf(";") > 0)
                {
                    _emailAddress.MailTo = _emailAddress.MailTo.Remove(_emailAddress.MailTo.Length - 1, 1);
                }

                mi.BccAddress = _emailAddress.MailBCC;
                mi.CCAddress  = _emailAddress.MailCC;



                #region Order Summary
                string MailContent = mi.FullText
                                     .Replace("&Firstname", _tOrder.FirstName)
                                     .Replace("&zorderid", _tOrder.OrderId.ToString())
                                     .Replace("&OrderDate", _tOrder.OrderDate.ToString("MM/dd/yyyy"))
                                     .Replace("&ztotalproductamount", _tOrder.TotalProductAmount.ToString("C", nfi))
                                     .Replace("&zTotalShipping", (_tOrder.TotalShipping).ToString("C", nfi))
                                     .Replace("&zTotalTax", _tOrder.TotalTax.ToString("C", nfi))
                                     .Replace("&zTotalOrderAmount", _tOrder.TotalOrderAmount.ToString("C", nfi))
                                     .Replace("&ShippingMethod", _tOrder.ShipMethod)
                                     .Replace("&ShippedDate", _tOrder.ShippedDate.Value.ToString("MM/dd/yyyy"));

                #endregion

                #region Order Detail
                string RepeatTemp = "";

                if (MailContent.IndexOf("&orderinfo") > 0)
                {
                    RepeatTemp = " <table width =\"100%\" cellpadding=\"1\"><tr><td >Item No</td><td>Description</td><td >Unit Price</td><td>Quantity</td></tr>";

                    foreach (TOrder_Line_ItemNu drItem in _orderDetails)
                    {
                        RepeatTemp = RepeatTemp + "<tr><td >" + drItem.PartNumber + "</td><td>" + drItem.ProductName
                                     + "</td><td >" + drItem.Price.ToString("C") + "</td><td>" + drItem.Quantity.ToString() + "</td></tr>";
                    }
                    RepeatTemp = RepeatTemp + "</TABLE>";
                }

                MailContent = MailContent.Replace("&orderinfo", RepeatTemp);
                #endregion

                #region Shipping Detail

                RepeatTemp = "";

                if (MailContent.IndexOf("&shipmentnfo") > 0)
                {
                    RepeatTemp = " <table  width =\"100%\" cellpadding=\"1\">";

                    int _packageNumber = 1;

                    TOrder_Line_Shipment_Carton _tOrder_Line_Shipment_Carton = new TOrder_Line_Shipment_Carton();
                    _result = _tOrder_Line_Shipment_Carton.getOrderLineShipmentCartonByOrderID(orderId, releaseID);
                    if (_result.Success == false)
                    {
                        return(_result);
                    }

                    EntityList cartonList = _result.ObjectList;



                    TOrder_Line_Shipment_ASN _tOrder_Line_Shipment_ASN = new TOrder_Line_Shipment_ASN();
                    _result = _tOrder_Line_Shipment_ASN.getOrderLineShipmentASNByOrderID(orderId, releaseID);
                    if (_result.Success == false)
                    {
                        return(_result);
                    }

                    EntityList asnList = _result.ObjectList;



                    foreach (TOrder_Line_Shipment_Carton _carton in cartonList)
                    {
                        if (asnList.Count != 0)
                        {
                            if (string.IsNullOrEmpty(_carton.PACKAGE_TRACE_ID) == false)
                            {
                                RepeatTemp = RepeatTemp + "<tr><td >Package " + _packageNumber.ToString() + "  Tracking Number:" + _carton.PACKAGE_TRACE_ID + "  " +
                                             "(<a href=\"{0}\">TrackOrder</a>)" + "</td></tr>";
                            }
                            else
                            {
                                RepeatTemp = RepeatTemp + "<tr><td >Package " + _packageNumber.ToString() + "  Tracking Number:N/A</td></tr>";
                            }

                            RepeatTemp = RepeatTemp + "<tr><td ><br /> <table width =\"100%\" cellpadding=\"1\"><tr><td > Item No</td>" +
                                         "<td>Description</td><td>Qty in Package</td></tr>";
                            foreach (TOrder_Line_Shipment_ASN _asn in asnList)
                            {
                                TOrder_Line_ItemNu _orderDetail = this.getOrderLine(_orderDetails, _asn);
                                RepeatTemp = RepeatTemp + " <tr><td >" + _orderDetail.PartNumber + "</td><td>" + _orderDetail.ProductName +
                                             "</td><td>" + Convert.ToInt16(Convert.ToDouble(_asn.PIECES_TO_MOVE)).ToString() + "</td></tr>";
                                RepeatTemp = RepeatTemp.Replace("{0}", _orderDetail.TrackingURL + _carton.PACKAGE_TRACE_ID);
                            }

                            RepeatTemp = RepeatTemp + "</table><br /></td></tr>";

                            _packageNumber++;
                        }
                    }


                    RepeatTemp = RepeatTemp + "</TABLE>";
                }

                MailContent = MailContent.Replace("&shipmentnfo", RepeatTemp);

                #endregion


                _mail.HtmlPart = new HtmlAttachment(MailContent);



                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_emailAddress.MailTo) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _emailAddress.MailTo.Split(';');
                        foreach (string _item in bcclist)
                        {
                            _mail.AddToAddress(new EmailAddress(_item));
                        }
                    }

                    _result.Table = _emailAddress.MailTo;
                }


                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddBccAddress(new EmailAddress(_item));
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddCcAddress(new EmailAddress(_item));
                    }
                }


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }

            return(_result);
        }
Esempio n. 5
0
        public ReturnValue SentInvoiceEmail(int invoiceId)
        {
            ReturnValue _result = new ReturnValue();

            string MailContent = "";

            string _emailTo = "";

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            Model.TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();

            try
            {
                #region generate Email Content

                TCustomer _tCustomer = new TCustomer();
                _result = _tCustomer.getCustomerByInvoiceId(invoiceId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tCustomer = _result.Object as TCustomer;


                _result = _tProgram_Email.getEmailTemplate("ShipInvoices");
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tProgram_Email = _result.Object as Model.TProgram_EmailTF;

                string _mailHtmlContent = System.Web.HttpUtility.HtmlDecode(System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml));


                MailContent = _mailHtmlContent.Replace("[CustomerName]", _tCustomer.FirstName);

                EmailMessage _mail = new EmailMessage();

                _mail.HtmlPart    = new HtmlAttachment(MailContent);
                _mail.FromAddress = new EmailAddress(_tProgram_Email.RespondTo);
                _mail.Subject     = _tProgram_Email.Subject;



                #endregion

                #region setup EmailMessage

                if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _emailTo = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _tCustomer.Email.Split(';');
                        foreach (string _item in bcclist)
                        {
                            if (string.IsNullOrEmpty(_item) == false)
                            {
                                _mail.AddToAddress(new EmailAddress(_item));
                            }
                        }
                    }

                    _emailTo = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(_tProgram_Email.BccAddress) == false)
                {
                    string[] bcclist = _tProgram_Email.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(_tProgram_Email.CCAddress) == false)
                {
                    string[] bcclist = _tProgram_Email.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }

                if (string.IsNullOrEmpty(_tCustomer.InvoiceEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.InvoiceEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                #endregion

                #region attached pdf

                string pdffilename = "";


                TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                _result = TecnifibreInvoicePDF.PrintInvoice(invoiceId);
                if (_result.Success == false)
                {
                    return(_result);
                }

                pdffilename = "Invoice/TFInvoice_" + invoiceId.ToString() + ".pdf";



                FileAttachment fileAttachment = new FileAttachment(new FileInfo(pdffilename));

                fileAttachment.ContentType = "application/pdf";

                _mail.AddMixedAttachment(fileAttachment);

                #endregion

                DotNetOpenMail.SmtpAuth.SmtpAuthToken token = new DotNetOpenMail.SmtpAuth.SmtpAuthToken(
                    System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"],
                    System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"]);


                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"]);
                server.SmtpAuthToken = token;

                if (_mail.Send(server) == false)
                {
                    _result.Success = false;
                }
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            #region Log App_Log_Mail
            App_Log_Mail _app_Log_Mail = new App_Log_Mail();
            // _app_Log_Mail.ProgramId = this.Owner.DefaultProgram.ProgramId;
            _app_Log_Mail.IsTest      = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString());
            _app_Log_Mail.CreatedOn   = System.DateTime.Now;
            _app_Log_Mail.AddressFrom = _tProgram_Email.RespondTo;
            _app_Log_Mail.AddressTo   = _emailTo;
            _app_Log_Mail.AddressBcc  = _tProgram_Email.BccAddress;
            _app_Log_Mail.Subject     = _tProgram_Email.Subject;
            _app_Log_Mail.Content     = MailContent;

            _app_Log_Mail.OId     = invoiceId.ToString();
            _app_Log_Mail.Success = _result.Success;
            _app_Log_Mail.Notes   = _result.ErrMessage;
            _app_Log_Mail.Type    = "ShippingInvoice";
            _app_Log_Mail.Save();

            #endregion


            return(_result);
        }
Esempio n. 6
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();


            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getCustomerInfo
            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            if (_tOrder.SourceId == 19)
            {
                _result.Code = 19;
                return(_result);
            }


            TCustomer _tCustomer = new TCustomer();
            _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tCustomer = _result.Object as TCustomer;



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(_tOrder.OrderId, releaseID);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _list = _result.ObjectList;

            if (_list.Count == 0)
            {
                return(_result);
            }

            _tOrder_Line_Item = _list[0] as TOrder_Line_Item;

            TShipMethod _tShipMethod = new TShipMethod();
            _result = _tShipMethod.getShipMethodById(_tOrder_Line_Item.ShipMethodId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipMethod = _result.Object as TShipMethod;


            TAddress _tBillAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.CustomerAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tBillAddress = _result.Object as TAddress;



            TAddress _tShipAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipAddress = _result.Object as TAddress;


            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getPaymentArrangementList(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _paymentList = _result.ObjectList;


            double _paymentApplied     = 0;
            double _estimatedAmountDue = 0;

            foreach (TPaymentArrangement _item in _paymentList)
            {
                if (_item.PayMethodId == 4)
                {
                    _estimatedAmountDue += _item.Amount;
                }
                else
                {
                    _paymentApplied += _item.Amount;
                }
            }



            #endregion


            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                #region filter the email content
                MailContent = MailContent.Replace("[CustomerName]", _tCustomer.FirstName == null ? "" : _tCustomer.FirstName.ToString());
                MailContent = MailContent.Replace("[OrderDate]", _tOrder.OrderDate.ToString("MM/dd/yyyy"));

                string siteURL = "http://admin.tecnifibreusa.com/";
                MailContent = MailContent.Replace("[WebSite]", siteURL);
                MailContent = MailContent.Replace("[OrderNumber]", _tOrder.AltOrderNum);
                MailContent = MailContent.Replace("[PONumber]", _tOrder.PONumber);
                MailContent = MailContent.Replace("[CustomerAcct]", _tCustomer.AltCustNum);
                MailContent = MailContent.Replace("[ShipMethod]", _tShipMethod.Description);

                MailContent = MailContent.Replace("[BillingAddress]", _tBillAddress.Company + "<br> " + _tBillAddress.Address1 + " " + _tBillAddress.Address2 + "<br>" + _tBillAddress.City + ", " + _tBillAddress.StateCode + " " + _tBillAddress.PostalCode);
                MailContent = MailContent.Replace("[ShippingAddress]", _tShipAddress.Company + "<br> " + _tShipAddress.Address1 + " " + _tShipAddress.Address2 + "<br>" + _tShipAddress.City + ", " + _tShipAddress.StateCode + " " + _tShipAddress.PostalCode);

                MailContent = MailContent.Replace("[SubTotal]", (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Tax]", "(" + Utilities.Round(_tOrder.TaxRate * 100, 2).ToString() + "%)" + (_tOrder.TotalTax - _tOrder.CompTax).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Shipping]", (_tOrder.TotalShipping - _tOrder.CompShipingCost).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Discount]", (_tOrder.TotalDiscountAmount + _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[OrderTotal]", _tOrder.TotalOrderAmount.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[PaymentApplied]", _paymentApplied.ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[EstimatedAmountDue]", _estimatedAmountDue.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[BFirstName]", _tBillAddress.FirstName);
                MailContent = MailContent.Replace("[BLastName]", _tBillAddress.LastName);
                MailContent = MailContent.Replace("[SFirstName]", _tShipAddress.FirstName);
                MailContent = MailContent.Replace("[SLastName]", _tShipAddress.LastName);


                StringBuilder OrderItemHTML = new StringBuilder();

                foreach (TOrder_Line_Item _item in _list)
                {
                    OrderItemHTML.Append("<tr>");
                    OrderItemHTML.Append("  <td>" + _item.LineNum + "</td>");
                    OrderItemHTML.Append("<td>" + _item.PartNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.ProductName + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Quantity + "</td>");
                    if (_item.ShippedDate != null)
                    {
                        OrderItemHTML.Append("<td>" + _item.ShippedDate.Value.ToString("MM/dd/yyyy") + "</td>");
                    }
                    else
                    {
                        OrderItemHTML.Append("<td></td>");
                    }
                    OrderItemHTML.Append("<td>" + _item.TrackingNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Price.ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.DiscountAmount + _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + ((_item.ActualPrice - _item.ComAmount) / _item.Quantity).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.ActualPrice - _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("</tr>");
                }
                #endregion


                MailContent = MailContent.Replace("[Items]", OrderItemHTML.ToString());


                _mail.HtmlPart = new HtmlAttachment(MailContent);


                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        _mail.AddToAddress(new EmailAddress(_tCustomer.Email));
                    }

                    _result.Table = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }


                if (string.IsNullOrEmpty(_tCustomer.OrderEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.OrderEmail));
                }
                if (string.IsNullOrEmpty(_tCustomer.SecondaryEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.SecondaryEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            return(_result);
        }
Esempio n. 7
0
        public virtual ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getOrderInfo and Check

            TOrder _tOrder = new TOrder();
            _result = _tOrder.getOrderById(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _tOrder = _result.Object as TOrder;


            if (_tOrder.OrderId == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exists --getOrderById";

                return(_result);
            }



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(orderId, releaseID);
            if (_result.Success == false)
            {
                return(_result);
            }

            EntityList _orderDetails = _result.ObjectList;


            if (_orderDetails.Count == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exists---getOrdersDetail";

                return(_result);
            }


            #endregion

            try
            {
                #region generate Email Content

                EmailMessage _mail = new EmailMessage();

                #region Order Summary

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                MailContent = MailContent
                              .Replace("{orderid}", _tOrder.AltOrderNum)
                              .Replace("{firstname}", _tOrder.FirstName)
                              .Replace("{shipmethod}", _tOrder.ShipMethodName)
                              .Replace("{ShipCarrier}", _tOrder.ShipCarrier)
                              .Replace("{CustomerName}", _tOrder.FirstName + " " + _tOrder.LastName)
                              .Replace("{trackingnumber}", _tOrder.TrackingNumber)
                              .Replace("{ShipDate}", _tOrder.ShippedDate.Value.ToString("MM/dd/yyyy"));

                #endregion

                TOrder_Line_Item _shipTo = _orderDetails[0] as TOrder_Line_Item;

                string shipinfo = _shipTo.ShipToAddress + "<br>" + _shipTo.ShipToCity + "," + _shipTo.ShipToState + " " + _shipTo.ShipToZip;

                MailContent = MailContent
                              .Replace("{shipmentnfo}", shipinfo);


                #region Shipping Detail

                string RepeatTemp = "";

                if (MailContent.IndexOf("{orderLine}") > 0)
                {
                    RepeatTemp = " <table  width =\"100%\" cellpadding=\"1\"><tr><td>SKU</td><td>Name</td><td>QTY</td></tr>";

                    foreach (TOrder_Line_Item _item in _orderDetails)
                    {
                        RepeatTemp = RepeatTemp + " <tr><td >" + _item.PartNumber + "</td><td>" + _item.ProductName +
                                     "</td><td>" + _item.Quantity.ToString() + "</td></tr>";
                    }

                    RepeatTemp = RepeatTemp + "</table>";
                }

                MailContent = MailContent.Replace("{orderLine}", RepeatTemp);

                #endregion



                #endregion

                _mail.HtmlPart = new HtmlAttachment(MailContent);

                #region setup EmailMessage

                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject.Replace("[Orderid]", _tOrder.AltOrderNum);

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tOrder.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _tOrder.Email.Split(';');
                        foreach (string _item in bcclist)
                        {
                            _mail.AddToAddress(new EmailAddress(_item));
                        }
                    }
                }

                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddBccAddress(new EmailAddress(_item));
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddCcAddress(new EmailAddress(_item));
                    }
                }

                #endregion

                _result.ObjectValue = _mail;
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }



            return(_result);
        }
Esempio n. 8
0
        public static ReturnValue SentEmail(TProgram_Email tProgram_Email, EmailFormat emailFormat, int oId, FileAttachment fileAttachment)
        {
            ReturnValue _result = new ReturnValue();

            bool IsTFTestMode = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTFTestMode"].ToString());

            if (tProgram_Email.ContentStatusId != 1)
            {
                return(_result);
            }

            EmailMessage _mail = new EmailMessage();

            if (string.IsNullOrEmpty(tProgram_Email.RespondToName) == true)
            {
                _mail.FromAddress = new EmailAddress(tProgram_Email.RespondTo);
            }
            else
            {
                _mail.FromAddress = new EmailAddress(tProgram_Email.RespondTo, tProgram_Email.RespondToName);
            }


            _mail.Subject = tProgram_Email.Subject;

            if (emailFormat == EmailFormat.Html || emailFormat == EmailFormat.Both)
            {
                _mail.HtmlPart = new HtmlAttachment(tProgram_Email.FullHtml);
            }
            if (emailFormat == EmailFormat.Text || emailFormat == EmailFormat.Both)
            {
                _mail.TextPart = new TextAttachment(tProgram_Email.FullText);
            }


            string _emailto = tProgram_Email.ToAddress;

            if (IsTFTestMode == true)
            {
                if (string.IsNullOrEmpty(Common.TestMailTo) == false)
                {
                    string[] ccList = Common.TestMailTo.Split(';');
                    foreach (string ccAddress in ccList)
                    {
                        _mail.AddToAddress(new EmailAddress(ccAddress));
                    }

                    _emailto = Common.TestMailTo;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(tProgram_Email.CCAddress) == false)
                {
                    string[] ccList = tProgram_Email.CCAddress.Split(';');
                    foreach (string ccAddress in ccList)
                    {
                        if (string.IsNullOrEmpty(ccAddress.Trim()) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(ccAddress));
                        }
                    }
                }


                if (string.IsNullOrEmpty(tProgram_Email.BccAddress) == false)
                {
                    string[] BccList = tProgram_Email.BccAddress.Split(';');
                    foreach (string bccAddress in BccList)
                    {
                        if (string.IsNullOrEmpty(bccAddress.Trim()) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(bccAddress));
                        }
                    }
                }
                if (string.IsNullOrEmpty(tProgram_Email.ToAddress) == false)
                {
                    string[] ToAddressList = tProgram_Email.ToAddress.Split(';');
                    foreach (string toAddress in ToAddressList)
                    {
                        if (string.IsNullOrEmpty(toAddress.Trim()) == false)
                        {
                            _mail.AddToAddress(new EmailAddress(toAddress));
                        }
                    }
                }
            }

            if (fileAttachment != null)
            {
                _mail.AddMixedAttachment(fileAttachment);
            }

            App_Log_Mail _mailLog = new App_Log_Mail();

            try
            {
                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"].ToString(), 25);

                DotNetOpenMail.SmtpAuth.SmtpAuthToken SmtpAuthToken =
                    new DotNetOpenMail.SmtpAuth.SmtpAuthToken(System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"].ToString(),
                                                              System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"].ToString());
                server.SmtpAuthToken = SmtpAuthToken;

                bool _success = _mail.Send(server);

                _mailLog.Success = _success;
                _mailLog.Notes   = "";
            }
            catch (Exception ex)
            {
                _mailLog.Success = false;
                _mailLog.Notes   = ex.ToString();
            }
            finally
            {
                _mailLog.AddressBcc  = "AddressBcc:" + (string.IsNullOrEmpty(tProgram_Email.BccAddress) ? "" : tProgram_Email.BccAddress) + " CCAddress:" + (string.IsNullOrEmpty(tProgram_Email.CCAddress) ? "" : tProgram_Email.CCAddress);
                _mailLog.AddressFrom = tProgram_Email.RespondTo;
                _mailLog.AddressTo   = _emailto;


                if (emailFormat == EmailFormat.Html || emailFormat == EmailFormat.Both)
                {
                    _mailLog.Content = tProgram_Email.FullHtml;
                }
                if (emailFormat == EmailFormat.Text || emailFormat == EmailFormat.Both)
                {
                    _mailLog.Content = tProgram_Email.FullText;
                }

                _mailLog.CreatedOn = System.DateTime.Now;
                _mailLog.Subject   = tProgram_Email.Subject;
                _mailLog.Type      = tProgram_Email.EmailTypeId.ToString();
                _mailLog.OId       = oId.ToString();
                _mailLog.IsTest    = IsTFTestMode;
                _mailLog.Save();
            }

            _result.Success    = _mailLog.Success.Value;
            _result.ErrMessage = _mailLog.Notes;

            if (string.IsNullOrEmpty(_mailLog.AddressTo) == true)
            {
                _result.Success = true;
            }

            return(_result);
        }