public async Task <IActionResult> Forgot([FromBody] string email) { User u = await _context.Users.FirstOrDefaultAsync(us => us.Email == email); if (u != null) { string code = RandomString(25); await _context.Confirmations.AddAsync(new Confirmation { Code = code, Expiration = DateTime.Now.AddDays(1), Type = 2, UserID = u.ID }); await _context.SaveChangesAsync(); EmailGeneratorDto ed = new EmailGeneratorDto { Button = "Şifrəmi yenilə", Text = "Şifrənizi yeniləmək üçün aşağıdakı keçidə klikləyin.", Url = String.Format("https://3sual.az/password/{0}/{1}", code, email), Header = "Şifrəmi unutmuşam" }; SendMail(email, "Şifrənin yenilənməsi", u.Name + " " + u.Surname, ed); return(Ok(new BasicResponse { Success = true, Message = "Şifrənizi yeniləmək üçün elektron poçtunuzu yoxlayın." })); } else { return(Ok(new BasicResponse { Success = false, Message = "Bu elektron poçt istifadə olunmayıb." })); } }
public static async void SendMail(string email, string type, string name, EmailGeneratorDto ed) { string htmlString = string.Format("<html><table style=\"max-width: 90%; min-width: 320px; width: 550px; margin: 0 auto; height: auto;\"><tr><td colspan=\"3\" style=\"background-image: url('https://www.razlee.com/wp-content/uploads/2017/08/Password-Reset-1-768x768-1.png'); background-position: center; background-size: contain; background-repeat: no-repeat; background-color: #1890FF; height: 250px;\"></td></tr><tr><td colspan=\"3\" style=\"background-color: #F0F2F5; height: auto; text-align: center;\"><div style=\"padding: 20px; height: auto;\"><table style=\"width: 100%;\"><tr><td colspan=\"3\" style=\"text-align: center; width: 100%;\"><h1 style=\"margin: .5rem 0; word-break: keep-all;\">{1}</h2></td></tr><tr><td colspan=\"3\" style=\"text-align: center; width: 100%;\"><h3 style=\"margin: .5rem 0;\">{2}</h3></td></tr><tr><td colspan=\"3\" style=\"text-align: center; width: 100%;\"><a href=\"{0}\" style=\"text-decoration: none; border:none; cursor: pointer; border-radius: 5px; color: #1890ff; font-size: 20px; padding: 15px 10px;\">{3}</a></td></tr></table></div></td></tr><tr><td colspan=\"3\" style=\"background-color: #1890FF; height: 50px; text-align: center;\"><a href=\"https://www.facebook.com/3sualaz-107176074259586/\"><img style=\"cursor: pointer; width: 30px; height: 30px;\" src=\"https://3sual.site/images/icons8-facebook-48.png\"/></a><a href=\"https://www.instagram.com/3sual.az/\"><img style=\"cursor: pointer; width: 30px; height: 30px;\" src=\"https://api.3sual.az/images/icons8-instagram-48.png\"/></a></td></tr></table></html>", ed.Url, ed.Header, ed.Text, ed.Button); var apiKey = "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"; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Bahruz Aydinli"); var subject = "AIHoldingTask | " + type; var to = new EmailAddress(email, name); var htmlContent = htmlString; var msg = MailHelper.CreateSingleEmail(from, to, subject, "", htmlContent); await client.SendEmailAsync(msg); }