Example #1
0
        public static async Task SendEmailAsync(List <FoodInCart> foodInCart)
        {
            _dateTime      = DateTime.Now.ToLocalTime();
            _emailMessage  = FoodInCart.CheckSummaryToEmail(foodInCart);
            _emailMessage += $"\n\n<br />Order was made : {_dateTime.ToShortDateString()} {_dateTime.ToShortTimeString()}";
            _emailMessage += $"\n<br />It will be delivered about : {_dateTime.AddMinutes(40).ToShortTimeString()}";

            Console.WriteLine("\nYour email");
            email = Console.ReadLine();


            MailAddress from    = new MailAddress("*****@*****.**", "MOE`S PUB");
            MailAddress to      = new MailAddress(email);
            MailMessage message = new MailMessage(from, to);

            message.Subject    = "Your order";
            message.Body       = _emailMessage;
            message.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

            smtp.Credentials = new NetworkCredential("*****@*****.**", "Aspire7720gG");
            smtp.EnableSsl   = true;

            await smtp.SendMailAsync(message);

            Logger.Log(Logger.Level.Debug, $"Email sending Async. With txt: {message}");
        }
Example #2
0
        public static void SendEmail(List <FoodInCart> foodInCart)
        {
            _dateTime      = DateTime.Now.ToLocalTime();
            _emailMessage  = FoodInCart.CheckSummaryToEmail(foodInCart);
            _emailMessage += $"\n\nOrder was made : {_dateTime.ToShortDateString()} {_dateTime.ToShortTimeString()}";
            _emailMessage += $"\nIt will be delivered about : {_dateTime.AddMinutes(40).ToShortTimeString()}";
            Console.WriteLine("Your email");
            email = Console.ReadLine();

            MailAddress from    = new MailAddress("*****@*****.**", "MOE`S PUB");
            MailAddress to      = new MailAddress(email);
            MailMessage message = new MailMessage(from, to);

            message.Subject    = "Your order";
            message.Body       = _emailMessage;
            message.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

            smtp.Credentials = new NetworkCredential("*****@*****.**", "Aspire7720gG");
            smtp.EnableSsl   = true;

            try
            {
                smtp.Send(message);
                Logger.Log(Logger.Level.Debug, $"Email sending. With txt: {message}");
            }
            catch (Exception)
            {
                Logger.Log(Logger.Level.Error, "Email error: no internet");
                throw new MailSenderException("No internet connection");
            }
        }
Example #3
0
        private static void AddToCart(List <Food> deserializedFood, int positionChosen, int quantity, List <FoodInCart> foodInCarts)
        {
            FoodInCart foodInCart = new FoodInCart(deserializedFood[positionChosen], quantity);

            foodInCarts.Add(foodInCart);
            Logger.Log(Logger.Level.Info, "Adding food to cart.");
        }