//Left here for Testing purposes, if someone has issue with it here it may be deleted freely public async Task SendGridFunc(EmailAddRequest model) { var msg = new SendGridMessage() { From = new EmailAddress(_config.Email), Subject = model.Subject, HtmlContent = model.HtmlContent }; msg.AddTo(new EmailAddress(model.To, model.RecipientName)); await Send(msg); }
public async Task Execute(EmailAddRequest model) { var msg = new SendGridMessage() { From = new EmailAddress(model.FromEmail, model.FromName), Subject = model.Subject, PlainTextContent = model.Content, HtmlContent = $"<strong>{model.Content}</strong>" }; msg.AddTo(new EmailAddress("*****@*****.**", "Test User")); await SendEmail(msg); }
public async Task <ActionResult <ItemResponse <EmailResponse> > > TestEmail(EmailAddRequest model) { int code = 200; BaseResponse response = null; try { EmailResponse item = await _service.TestEmail(model); response = new SuccessResponse(); } catch (Exception ex) { response = new ErrorResponse(ex.Message); code = 500; } return(StatusCode(code, response)); }
public async Task <ActionResult <SuccessResponse> > ExecuteAsync(EmailAddRequest model) { BaseResponse result; int statusCode = 200; try { await _emailService.Execute(model); result = new SuccessResponse(); } catch (Exception ex) { base.Logger.LogError(ex.ToString()); result = new ErrorResponse(ex.Message); statusCode = 500; } return(StatusCode(statusCode, result)); }
public async Task <ActionResult <ItemResponse <User> > > GetByEmail(string email) { int iCode = 200; BaseResponse response = null; try { User user = _userService.GetByEmail(email); if (user == null) { iCode = 404; response = new ErrorResponse("Email not found."); } else { Guid guid = Guid.NewGuid(); _userTokenService.AddForgotPassword(user.Id, guid); EmailAddRequest emailBase = new EmailAddRequest(); emailBase.From = user.Email; string userEmail = emailBase.From; string directory = Environment.CurrentDirectory; string path = Path.Combine(directory, "EmailTemplates\\ResetPasswordEmail.html"); string htmlContent = System.IO.File.ReadAllText(path); await _service.ResetPasswordEmail(userEmail, htmlContent, _sendGridConfig.Secret, _sendGridConfig.Email, guid); response = new ItemResponse <User> { Item = user }; }; } catch (Exception ex) { iCode = 500; base.Logger.LogError(ex.ToString()); response = new ErrorResponse($"Generic Error: {ex.Message}"); } return(StatusCode(iCode, response)); }
public async Task <ActionResult> Register(UserAddRequest model) { ObjectResult result = null; try { int id = _userService.Create(model); Guid guid = Guid.NewGuid(); _userTokenService.Add(id, guid); EmailAddRequest emailBase = new EmailAddRequest(); emailBase.From = model.Email; string email = emailBase.From; string directory = Environment.CurrentDirectory; string path = Path.Combine(directory, "EmailTemplates\\ConfirmEmail.html"); string htmlContent = System.IO.File.ReadAllText(path); await _service.ConfirmEmail(email, htmlContent, _sendGridConfig.Secret, _sendGridConfig.Email, guid); ItemResponse <int> response = new ItemResponse <int>() { Item = id }; result = Created201(response); } catch (Exception ex) { base.Logger.LogError(ex.ToString()); ErrorResponse response = new ErrorResponse(ex.Message); result = StatusCode(500, response); } return(result); }