public async Task <HttpResponseMessage> PostEmailPreferences([FromBody] UserEmailModel model) { try { var response = await Task.Run(() => { var user = DataContext.AspNetUsers.Find(model.UserId); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, String.Format("That user does not exist: {0}", model.UserId))); } if (user.UserPreference == null) { user.UserPreference = new Data.UserPreference(); } user.UserPreference.EmailMyWonders = model.EmailMyWonders; user.UserPreference.Reminder = DataContext.Reminders.SingleOrDefault(r => r.Id == model.ReminderId); DataContext.Commit(); return(Request.CreateResponse(HttpStatusCode.OK)); }); return(response); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
/// <summary> /// /// </summary> /// <param name="message"></param> /// <param name="user"></param> /// <param name="useSSL"></param> /// <returns></returns> public static async Task <bool> SendAsync(UserEmailModel message, string user = "******", bool useSSL = true) { // Plug in your email service here to send an email. var emailhost = System.Configuration.ConfigurationManager.AppSettings["EmailSMTPHost"]; var emailport = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["EmailSMTPPort"]); var emailuser = System.Configuration.ConfigurationManager.AppSettings[user + "EmailUser"]; var emailpass = System.Configuration.ConfigurationManager.AppSettings[user + "EmailPass"]; var mmessage = new MailMessage(); mmessage.To.Add(new MailAddress(message.Destination)); mmessage.From = new MailAddress(emailuser); // replace with valid value mmessage.Subject = message.Subject; mmessage.Body = message.Body; mmessage.IsBodyHtml = true; if (message.Email != null && message.Email != "") { mmessage.ReplyTo = new MailAddress(message.Email); } using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = emailuser, Password = emailpass }; smtp.Credentials = credential; smtp.Host = emailhost; smtp.Port = emailport; smtp.EnableSsl = useSSL; await smtp.SendMailAsync(mmessage).ConfigureAwait(true); } return(true); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } ApiResult result = new ApiResult(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Constants.API_BASE_URL); UserVerifyInfo userVerifyInfo = userVerifyModel.ToInfo(); using (var response = await client.PostAsJsonAsync <UserVerifyInfo>("VerifyCode", userVerifyInfo)) { string apiResponse = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <ApiResult>(apiResponse); if (result.resultCode == ResultCode.SUCCESS) { UserEmailModel userEmailModel = new UserEmailModel(); userEmailModel.UserName = userVerifyInfo.UserName; userEmailModel.EmailAddr = userVerifyInfo.EmailAddr; HttpContext.Session.Set("_username", Encoding.ASCII.GetBytes(userVerifyInfo.UserName)); return(RedirectToPage("./ResetPassword")); } } } ViewData["Error"] = result.errMsg; _logger.LogInformation(result.errMsg); return(Page()); }
public IActionResult SendRestoreEmail(UserEmailModel model) { try { _serviceAuth.sendRestoreEmail(model.Email); return(Ok("link to restore your password sent to email")); } catch (ValidationException ex) { return(BadRequest(ex.Message)); } }
public ActionResult SendMail(UserEmailModel model) { if (!ModelState.IsValid) { //TODO: Have a proper error screen return(RedirectToAction("Index")); } model.Destination = "*****@*****.**"; MailingService.Send(model); return(RedirectToAction("FeedbackSuccess")); }
public ActionResult SendFeedback(string msg, string loc) { String uid = ""; uid = User.Identity.GetUserId(); UserEmailModel message = new UserEmailModel(); message.Email = ""; message.Name = "ZapRead Feedback"; message.Subject = "ZapRead Feedback"; message.Body = msg + Environment.NewLine + " Location: " + loc + Environment.NewLine + Environment.NewLine + " User: "******"*****@*****.**"; MailingService.Send(message); return(Json(new { result = "success" })); }
static void Main(string[] args) { async void SendMail(string email, string subject, string message) { SendGridMailService sendGridMailService = new SendGridMailService(); await sendGridMailService.SendEmail(email, subject, message); } try { RabbitMQService _rabbitMQService = new RabbitMQService(); using (var connection = _rabbitMQService.GetRabbitMQConnection()) { //kanal olusturma using (var channel = connection.CreateModel()) { //kuyruk olusturma channel.QueueDeclare("mailQueque", false, false, false, null); var consumer = new EventingBasicConsumer(channel); channel.BasicConsume("mailQueque", true, consumer); consumer.Received += (s, e) => { string serializeJson = Encoding.UTF8.GetString(e.Body.Span); UserEmailModel user = JsonSerializer.Deserialize <UserEmailModel>(serializeJson); SendMail(user.Email, user.Title, user.Message); Console.WriteLine($"Email Başarıyla {user.Email} gönderildi"); }; Console.ReadLine(); //rabbitmq gönderme } } } catch (Exception e) { Console.WriteLine($"Hata Oldu {e.Message}"); } Console.Read(); }
public void SaveUserProfile_Success() { var emailModel = new UserEmailModel() { EmailID = 1, Email = "*****@*****.**", UserEmailID = 1, IsPrimary = true, ForceRollback = true }; var model = new UserProfileViewModel() { UserID = _userID, IsTemporaryPassword = false, Emails = new List <UserEmailModel>() { emailModel }, Phones = new List <UserPhoneModel>(), Addresses = new List <UserAddressModel>(), ForceRollback = true }; var response = _repository.SaveUserProfile(model, isMyProfile); Assert.IsTrue(response != null, "Response can't be null"); Assert.IsTrue(response.ResultCode == 0, "User profile could not be saved"); }