/// <summary> /// Create and send a new mail /// </summary> /// <param name="authToken">Access token to use</param> /// <param name="characterId">An EVE character ID</param> /// <param name="mailInput">The mail to send</param> /// <returns>Mail ID</returns> public ESIResponse <int> SendMail(string authToken, int characterId, SendMailInput mailInput) { var request = RestRequestHelper.CreateAuthorizedPostRequest($"characters/{characterId}/mail/", authToken); request.AddJsonBody(mailInput); return(_httpClient.Execute <int>(request)); }
public async Task <SendMailPayload> SendGroupMail( SendMailInput input, [Service] IMailService _mailService, CancellationToken cancellationToken) { var result = await _mailService.SendGroupMailAsync(input.subject, input.body, input.adresses, cancellationToken); return(result); }
public void SendMailTest() { var input = new SendMailInput { From = "PolyHx <*****@*****.**>", To = new [] { "*****@*****.**" }, Subject = "Sponsorship PolyHx", Html = "<h3>I want to give you some money</h3>" }; var res = _mailService.SendEmail(input).Result; Assert.IsTrue(res); }
public Task <IActionResult> SendConfirmEmail(AskResetPasswordInput input) { return(Task.Run <IActionResult>(async() => { var user = _db.Single <User>(c => c.Username == input.Username); if (user == null) { return new StatusCodeResult((int)HttpStatusCode.BadRequest); } var confirmEmail = _db.Single <ConfirmEmail>(r => r.UserId == user.Id && !r.Used); if (confirmEmail == null) { return BadRequest(); } confirmEmail.Uuid = Guid.NewGuid().ToString(); _db.Update <ResetPassword>(confirmEmail.Id, new Dictionary <string, object> { { "Uuid", confirmEmail.Uuid } }); var mailInput = new SendMailInput { From = "PolyHx <*****@*****.**>", To = new[] { user.Username }, Subject = "Confirmer votre compte | Confirm your account", Template = "confirm_email", Html = "<html></html>", Text = "Text", Variables = new Dictionary <string, string> { { "url", $"{Environment.GetEnvironmentVariable("CONFIRM_EMAIL_URL")}/{confirmEmail.Uuid}" } } }; await _mailService.SendEmail(mailInput); return Ok(new {}); })); }
public void HtmlOnlyMailInput() { var input = new SendMailInput { From = "PolyHx <*****@*****.**>", To = new [] { "*****@*****.**" }, Subject = "Sponsorship PolyHx", Html = "<h3>I want to give you some money</h3>" }; var content = input.ToString(); Assert.AreEqual("{\"from\":\"PolyHx <*****@*****.**>\"," + "\"to\":[\"[email protected]\"]," + "\"subject\":\"Sponsorship PolyHx\"," + "\"text\":null," + "\"html\":\"<h3>I want to give you some money</h3>\"," + "\"template\":null," + "\"variables\":null}", content); }
public async Task <bool> SendEmail(SendMailInput input) { var content = new StringContent(input.ToString(), Encoding.UTF8, "application/json"); HttpResponseMessage result; try { var token = await _stsService.GetAccessToken(); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); result = await _httpClient.PostAsync(ApiUrl + "/email", content); } catch (Exception e) { Console.WriteLine(e); throw; } return(result.StatusCode == HttpStatusCode.OK || result.StatusCode == HttpStatusCode.Created); }
public void TemplateVariablesInput() { var input = new SendMailInput { From = "PolyHx <*****@*****.**>", To = new [] { "*****@*****.**" }, Subject = "Sponsorship PolyHx", Template = "test", Variables = new Dictionary <string, string> { { "name", "PolyHx" } } }; var content = input.ToString(); Assert.AreEqual("{\"from\":\"PolyHx <*****@*****.**>\"," + "\"to\":[\"[email protected]\"]," + "\"subject\":\"Sponsorship PolyHx\"," + "\"text\":null," + "\"html\":null," + "\"template\":\"test\"," + "\"variables\":{\"name\":\"PolyHx\"}}", content); }
public Task <IActionResult> CreateAttendee(AttendeeRegisterInput input) { return(Task.Run <IActionResult>(async() => { if (!ModelState.IsValid) { Console.WriteLine(input); return BadRequest(); } if (!ValidatePassword(input.Password)) { return BadRequest(new { Message = "Password not valid" }); } var user = _db.Single <User>(u => u.Username == input.Username.ToLower()); if (user != null) { return new StatusCodeResult((int)HttpStatusCode.Conflict); } try { var hashedPassword = BCrypt.Net.BCrypt.HashPassword(input.Password); user = new User { Username = input.Username.ToLower(), Password = hashedPassword, RoleId = _db.Single <Role>(r => r.Name == "attendee").Id, Validated = false }; _db.Add(user); var confirmEmail = new ConfirmEmail { UserId = user.Id, Uuid = Guid.NewGuid().ToString() }; _db.Add(confirmEmail); // Create confirm password doc var mailInput = new SendMailInput { From = "PolyHx <*****@*****.**>", To = new[] { user.Username }, Subject = "Confirmer votre compte | Confirm your account", Template = "confirm_email", Html = "<html></html>", Text = "Text", Variables = new Dictionary <string, string> { { "url", $"{Environment.GetEnvironmentVariable("CONFIRM_EMAIL_URL")}/{confirmEmail.Uuid}" } } }; var res = await _mailService.SendEmail(mailInput); return Ok(new { success = true, userId = user.Id }); } catch (Exception) { return new StatusCodeResult((int)HttpStatusCode.InternalServerError); } })); }
public IActionResult Create(AskResetPasswordInput input) { Task.Run(async() => { Console.WriteLine("Sending the reset password email to the user"); if (!ModelState.IsValid) { Console.WriteLine("The model isn't valid"); return; } var user = _db.Single <User>(c => c.Username.ToLower() == input.Username.ToLower()); if (user == null) { Console.WriteLine("No user found with this username {0}", input.Username); return; } ResetPassword resetPassword; try { resetPassword = _db.Single <ResetPassword>(c => c.UserId == user.Id && !c.Used); } catch (Exception) { Console.WriteLine("An error occured while getting the reset password."); resetPassword = null; } if (resetPassword == null) { resetPassword = new ResetPassword { UserId = user.Id, Uuid = Guid.NewGuid().ToString() }; _db.Add(resetPassword); } else { resetPassword.Uuid = Guid.NewGuid().ToString(); _db.Update <ResetPassword>(resetPassword.Id, new Dictionary <string, object> { { "Uuid", resetPassword.Uuid } }); } var mailInput = new SendMailInput { From = "CS Games <*****@*****.**>", To = new[] { user.Username }, Subject = "Réinitialisation du Mot de Passe | Password Reset", Template = "password_reset", Html = "<html></html>", Text = "Text", Variables = new Dictionary <string, string> { { "url", $"{Environment.GetEnvironmentVariable("RESET_PASSWORD_URL")}/{resetPassword.Uuid}" } } }; var res = await _mailService.SendEmail(mailInput); Console.WriteLine("The email was sent successfully"); }); return(Ok()); }