/// <summary> /// Send Customer ComebackMail /// </summary> /// <param name="v"></param> /// <returns></returns> private static bool DoEmailWork2(string v) { try { //List all customers List <Customer> e = DataLayer.ListCustomers(); //List all orders List <Order> f = DataLayer.ListOrders(); //loop through list of customers foreach (Customer c in e) { // We send mail if customer hasn't put an order bool Send = true; //loop through list of orders to see if customer don't exist in that list foreach (Order o in f) { // Email exists in order list if (c.Email == o.CustomerEmail) { //We don't send email to that customer Send = false; } } //Send if customer hasn't put order if (Send == true) { //Create a new MailMessage System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(); //Add customer to reciever list m.To.Add(c.Email); //Add subject m.Subject = "We miss you as a customer"; //Send mail from [email protected] m.From = new System.Net.Mail.MailAddress("*****@*****.**"); //Add body to mail m.Body = "Hi " + c.Email + "<br>We miss you as a customer. Our shop is filled with nice products. Here is a voucher that gives you 50 kr to shop for." + "<br>Voucher: " + v + "<br><br>Best Regards,<br>Our Team"; #if DEBUG //Don't send mails in debug mode, just write the emails in console Console.WriteLine("Send mail to:" + c.Email); #else //Create a SmtpClient to our smtphost: yoursmtphost System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost"); //Send mail smtp.Send(m); #endif } } //All mails are sent! Success! return(true); } catch (Exception) { //Something went wrong :( return(false); } }