private void SendMail(string[] UserIDs) { string SaveTheDateConnection = ConfigurationManager.ConnectionStrings["iMascotConnectionString"].ConnectionString; using (iMascotModelDataContext SaveTheDateDB = new iMascotModelDataContext(SaveTheDateConnection)) { var templateInfo = SaveTheDateDB.EmailTemplates.FirstOrDefault(ab => ab.TemplateID == 1); if (templateInfo == null) { return; } string MailSubject = templateInfo.MailSubject ; foreach (string UserId in UserIDs) { if (!string.IsNullOrEmpty(UserId)) { Guid providerUserKey = new Guid(UserId); MembershipUser user = Membership.GetUser(providerUserKey); var usersToken = from ab in SaveTheDateDB.MailTokens where ab.UserId == providerUserKey select ab; SaveTheDateDB.MailTokens.DeleteAllOnSubmit(usersToken); SaveTheDateDB.SubmitChanges(); MailToken mtoken = new MailToken(); mtoken.UserId = providerUserKey; mtoken.UserName = user.UserName; mtoken.EmailToken = Guid.NewGuid(); SaveTheDateDB.MailTokens.InsertOnSubmit(mtoken); SaveTheDateDB.SubmitChanges(); MailMessage msg = new MailMessage(); string MailBody = templateInfo.MailBody.Replace("[!UserName]", user.UserName).Replace("[!Url]" , "<a href=\"" + BaseVirtualAppPath + "/ResetPassword.aspx?MailToken=" + mtoken.EmailToken.ToString() + "\">here</a>"); msg.To.Add(user.Email); msg.Subject = MailSubject.Trim(); msg.IsBodyHtml = true; msg.Body = MailBody; SmtpClient smtp = new SmtpClient(); smtp.EnableSsl = true; smtp.Send(msg); var userInfo = SaveTheDateDB.Guests.First(ab => ab.UserId.ToString() == UserId); userInfo.InvitationMail = DateTime.Now; SaveTheDateDB.SubmitChanges(); } } } }
partial void UpdateMailToken(MailToken instance);
partial void DeleteMailToken(MailToken instance);
partial void InsertMailToken(MailToken instance);