Пример #1
0
        private void EmailMember()
        {
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  smtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(this.GetUserAccount().Email);
                mail.Subject = "Reservation Summary!";

                string bodyMessage = "Thank you for your order! \nYou may reply to this email at any time to set up a time for pick up or delivery.\n\nDetails:\n\n====================\n";
                foreach (IBook item in this.GetCart().Contents)
                {
                    bodyMessage += $"Library ID: {item.LibraryID}\n{item.Title}\n by: {item.Author}\n====================\n";
                }

                bodyMessage += "\n\nYou may reply to this email at any time if you have questions or to cancel your order.";
                mail.Body    = bodyMessage;

                smtpServer.Port        = 587;
                smtpServer.Credentials = new System.Net.NetworkCredential("mattslibrarymanager", "8122Password");
                smtpServer.EnableSsl   = true;

                HandleSentEmail sentEmailHandler = () => {
                    smtpServer.Dispose();
                    mail.Dispose();
                    RedirectToAction("BrowseInventory");
                };
                smtpServer.SendAsync(mail, sentEmailHandler);
            }
            catch (Exception e) {
                string message = e.Message;
            }
        }
Пример #2
0
        private void EmailAdministrator()
        {
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  smtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add("*****@*****.**");
                mail.Subject = "Book Reservation!";

                string bodyMessage = $"Member: {this.GetUserAccount().FirstName} {this.GetUserAccount().LastName} \n" +
                                     $"Email: {this.GetUserAccount().Email}\n\n" +
                                     $"Reserve these items:\n====================\n";
                foreach (IBook item in this.GetCart().Contents)
                {
                    bodyMessage += $"Item# {item.LibraryID}\n{item.Title}\n====================\n";
                }
                mail.Body = bodyMessage;

                smtpServer.Port        = 587;
                smtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "8122Password");
                smtpServer.EnableSsl   = true;

                HandleSentEmail sentEmailHandler = () => {
                    smtpServer.Dispose();
                    mail.Dispose();
                    RedirectToAction("BrowseInventory");
                };
                smtpServer.SendAsync(mail, sentEmailHandler);
            }
            catch (Exception e) {
                string message = e.Message;
            }
        }