public bool GenerateEmailOTP(string emailId) { try { var emailSender = new ADEmailSender.EmailSender(); //Generate random alpha numeric number START StringBuilder otpString = new StringBuilder(); char c; Random rnd = new Random(DateTime.Now.Millisecond); while (otpString.Length < 7) { c = Convert.ToChar(rnd.Next(48, 123)); if (char.IsLetterOrDigit(c)) { otpString.Append(c); } } //Ends string msgTosend = "Your one time password is " + otpString + " . you received this message because you tried to login to Portal."; emailSender.SendOTPToEmail("*****@*****.**", "Tintin@579", emailId, msgTosend); OTPEmail objEmail = new OTPEmail(emailId, otpString.ToString()); return(_loginRepo.StoreOTPtoMemory(objEmail)); } catch (Exception ex) { throw ex; } }
public bool StoreOTPtoMemory(OTPEmail otpDetails) { if (lstAccounts.ContainsKey(otpDetails.EmailId)) { lstAccounts.Remove(otpDetails.EmailId); } lstAccounts.Add(otpDetails.EmailId, otpDetails); return(true); }
public async Task <ActionResult> Send([FromBody] OTPEmail otp) { using (_logger.BeginScope("Send email", otp)) { using (var http = _clientFactory.CreateClient("O365")) { var msg = new { message = new { subject = "OTP Code", body = new { contentType = "Text", content = $"Please use {otp.otp} to confirm your email address" }, toRecipients = new[] { new { emailAddress = new { address = otp.email } } } }, saveToSentItems = false }; var resp = await http.SendAsync( new HttpRequestMessage(HttpMethod.Post, http.BaseAddress + $"users/[email protected]/sendMail") { Content = new StringContent(JsonConvert.SerializeObject(msg), Encoding.UTF8, "application/json") }); if (resp.IsSuccessStatusCode) { return(Ok()); } else { new Exception(resp.ReasonPhrase); } } } return(Ok()); }
public bool StoreOTPtoDB(OTPEmail otpDetails) { throw new NotImplementedException(); }