public static void SendInfoNewDealsUsers(int discount, int offeres)
    {
        if (offeres > 0)
        {
            CarRentalDataContext db = new CarRentalDataContext();
            var users = from u in db.UserLinks
                        select new
            {
                UserName = u.FName + " " + u.LName,
                u.Email
            };

            foreach (var item in users)
            {
                try
                {
                    MailMessage mail       = new MailMessage();
                    SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                    mail.IsBodyHtml = true;
                    mail.From       = new MailAddress("*****@*****.**");
                    mail.To.Add(item.Email);
                    mail.Subject = "Rental Car NEW OFFER!";
                    mail.Body    = "<div>Hello " + item.UserName + "!<br />We have NEW " + discount + "% Limited offer for first " + offeres + " users!<br /> For more details visit our website.</div>";

                    SmtpServer.Port        = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Qwerty12480");
                    SmtpServer.EnableSsl   = true;

                    SmtpServer.Send(mail);
                }
                catch (Exception ex)
                {
                }
            }
        }
    }
示例#2
0
 public VehicleRepository(CarRentalDataContext context)
 {
     _context = context;
 }
    public static void SendInfoNewDealsUsers(int discount, int offeres)
    {
        if (offeres > 0)
        {
            CarRentalDataContext db = new CarRentalDataContext();
            var users = from u in db.UserLinks
                        select new
                        {
                            UserName = u.FName + " " + u.LName,
                            u.Email
                        };

            foreach (var item in users)
            {
                try
                {
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                    mail.IsBodyHtml = true;
                    mail.From = new MailAddress("*****@*****.**");
                    mail.To.Add(item.Email);
                    mail.Subject = "Rental Car NEW OFFER!";
                    mail.Body = "<div>Hello " + item.UserName + "!<br />We have NEW " + discount + "% Limited offer for first " + offeres + " users!<br /> For more details visit our website.</div>";

                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Qwerty12480");
                    SmtpServer.EnableSsl = true;

                    SmtpServer.Send(mail);
                }
                catch (Exception ex)
                {
                }
            }
        }
    }