public ConfirmationCode SendPassword(string Email, SendPassword Source) { return(_IMemberDL.SendPassword(Email, Source)); }
public ConfirmationCode SendPassword(string Email, SendPassword Source) { _Connection.Sheet = "Fundraisers"; string to = Email; string from = "f"; //From address ConfirmationCode cd = new ConfirmationCode(); try { MailMessage message = new MailMessage(from, to); message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; string mailbody; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Gmail smtp System.Net.NetworkCredential basicCredential1 = new System.Net.NetworkCredential(); client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = basicCredential1; switch (Source) { case Entities.SendPassword.ForgotPassword: var range = $"{_Connection.Sheet}!A:AP"; SpreadsheetsResource.ValuesResource.GetRequest request = _Connection.Service.Spreadsheets.Values.Get(_Connection.SpreadsheetId, range); var response = request.Execute(); IList <IList <object> > values = response.Values; if (values != null && values.Count > 0) { foreach (var row in values) { if (row.Count != 0) { if (row[8].ToString().ToLower() == Email.ToLower()) { mailbody = "Your password is: " + row[2].ToString(); message.Subject = "Your Password"; message.Body = mailbody; try { client.Send(message); cd.EmailStatus = Status.EmailSent; return(cd); } catch { cd.EmailStatus = Status.ProblemSending; return(cd); } } } } } cd.EmailStatus = Status.EmailNotFound; return(cd); case Entities.SendPassword.NewMember: Random rnd = new Random(); int length = 10; string rndPassword = ""; for (var i = 0; i < length; i++) { rndPassword += ((char)(rnd.Next(1, 26) + 64)).ToString(); } mailbody = "Your Confirmation Code is: " + rndPassword; message.Subject = "Confirmation Code"; message.Body = mailbody; try { client.Send(message); cd.EmailStatus = Status.EmailSent; cd.Code = rndPassword; return(cd); } catch { cd.EmailStatus = Status.ProblemSending; return(cd); } default: return(null); } } catch { cd.EmailStatus = Status.IncorrectFormat; return(cd); } }
public ChangePassWordForm() { InitializeComponent(); SendPass = setPassword; }