示例#1
0
        public void OrderProcess(CartFunctions cartFunctions, Order order)
        {
            using (var smpt = new SmtpClient())
            {
                smpt.UseDefaultCredentials = false;
                smpt.Credentials           = new NetworkCredential(email.Login, email.Password);
                smpt.Host      = email.ServerName;
                smpt.Port      = email.Port;
                smpt.EnableSsl = email.Ssl;

                if (email.File)
                {
                    smpt.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smpt.PickupDirectoryLocation = email.Target;
                    smpt.EnableSsl = false;
                }

                StringBuilder builder = new StringBuilder()
                                        .AppendLine("Zamówienie:")
                                        .AppendLine("");

                foreach (var m in cartFunctions.Cart)
                {
                    var sum = m.Product.Price * m.Number;
                    builder.AppendFormat("{0} x {1}     {2:c}", m.Product.Name, m.Number, sum)
                    .AppendLine("");
                }


                builder.AppendFormat("W sumie:     {0:c}", cartFunctions.SumItem())
                .AppendLine("")
                .AppendLine("")
                .AppendLine("Adres dostawy:")
                .AppendLine(order.FirstName)
                .AppendLine(order.LastName)
                .AppendLine(order.Phone)
                .Append(order.Street + " ").Append(order.House).AppendLine("/" + order.Apartment)
                .Append(order.City + ", ").AppendLine(order.Zip);

                MailMessage message = new MailMessage
                                      (
                    email.UserMail,
                    email.AdminMail,
                    "Nowe zamówienie",
                    builder.ToString()
                                      );

                if (email.File)
                {
                    message.BodyEncoding = Encoding.UTF8;
                }

                smpt.Send(message);
            }
        }