public static EmailStatus SendEmail(ViewEmail from, string toEmail, string subject, string textMessage, string userID) { if (String.IsNullOrWhiteSpace(from.Title)) { from.Title = "آنلاین استور"; } string body = renderEmailBody(textMessage); var status = EmailStatus.Delivered; try { var message = new MailMessage(); message.From = new MailAddress(from.EmailAddress, from.Title, System.Text.UTF8Encoding.UTF8); message.To.Add(new MailAddress(toEmail)); message.Subject = subject; message.Body = body; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = from.EmailAddress.Trim(), Password = from.Password.Trim() }; smtp.Credentials = credential; smtp.Host = "mail.online-store.com"; smtp.Port = 25; smtp.EnableSsl = false; smtp.Send(message); } } catch (Exception ex) { status = EmailStatus.Failed; textMessage += "\n Error:" + ex.Message; } var log = new EmailLog { From = StaticValues.InfoEmail, To = toEmail, Message = textMessage, IP = Utilities.GetIP(), LastUpdate = DateTime.Now, UserID = userID, Status = status, Key = Guid.NewGuid().ToString() }; EmailLogs.Insert(log); return(status); }
public async Task <PostResponseModel> RegisterVendor(RegisterVendorRequestModel vendorDetailsRequestModel) { PostResponseModel postResponseModel = new PostResponseModel(); RegisterVendor registerUser = new RegisterVendor() { VendorName = vendorDetailsRequestModel.VendorName, VendorEmail = vendorDetailsRequestModel.VendorEmail, VendorMobile = vendorDetailsRequestModel.VendorMobile, VendorLandline = vendorDetailsRequestModel.VendorLandline, AddressLine = vendorDetailsRequestModel.AddressLine, City = vendorDetailsRequestModel.City, State = vendorDetailsRequestModel.State, PinCode = vendorDetailsRequestModel.PinCode }; var registerVendorResponse = await _vendorAuthenticationRepository.RegisterVendor(registerUser); postResponseModel.IsAlreadyExists = registerVendorResponse.IsUserExists; if (!postResponseModel.IsAlreadyExists && registerVendorResponse.Success) { var emailBody = "Hello !!!"; var emailSubject = "Vendor Register"; var emailResponse = await _messageSenderUtility.SendEmail(emailBody, emailSubject, vendorDetailsRequestModel.VendorEmail); postResponseModel.Success = emailResponse.IsEmailSend; //Log email EmailLogs emailLogDetails = new EmailLogs() { FromEmailAddress = emailResponse.FromEmailAddress, ToEmailAddress = emailResponse.ToEmailAddress, Subject = emailSubject, Body = emailBody, IsProduction = emailResponse.IsProductionEnvironment, IsSend = emailResponse.IsEmailSend, ApplicationId = (int)ApplicationType.Vendor, FromUserType = "System", ToUserType = "Vendor", ToUserId = registerVendorResponse.Content.VendorId }; await _loggingRepository.LogEmailTransaction(emailLogDetails); } else { postResponseModel.Success = registerVendorResponse.Success; } return(postResponseModel); }
public static int LogEmailToDB(EmailLogs email) { var oParams = new DBParamCollection { { "@SendBy", email.SendBy }, { "@SendTo", email.SendTo }, { "@EmailMessage", email.EmailMessage }, { "@EmailSubject", email.EmailSubject } }; using (var command = new DBCommand("[dbo].[upsINSERT_EmailLogs]", QueryType.StoredProcedure, oParams)) { return(command.Execute()); } }
public async Task <PostResponseModel> ConfirmRegistration(int vendorId) { PostResponseModel postResponseModel = new PostResponseModel(); var passwordSalt = AuthenticateUtility.CreatePasswordSalt(); var password = AuthenticateUtility.GetRandomAlphanumericString(12); var encryptedPassword = AuthenticateUtility.GeneratePassword(password, passwordSalt); var registerVendorResponse = await _vendorRepository.ConfirmRegistration(vendorId, encryptedPassword, passwordSalt); postResponseModel.IsAlreadyExists = registerVendorResponse.IsUserExists; if (!postResponseModel.IsAlreadyExists && registerVendorResponse.Success) { var emailBody = "Your password: "******"Confirm Your Registration"; var emailResponse = await _messageSenderUtility.SendEmail(emailBody, emailSubject, registerVendorResponse.Content.VendorEmail); postResponseModel.Success = emailResponse.IsEmailSend; //Log email EmailLogs emailLogDetails = new EmailLogs() { FromEmailAddress = emailResponse.FromEmailAddress, ToEmailAddress = emailResponse.ToEmailAddress, Subject = emailSubject, Body = emailBody, IsProduction = emailResponse.IsProductionEnvironment, IsSend = emailResponse.IsEmailSend, ApplicationId = (int)ApplicationType.Admin, FromUserType = "System", ToUserType = "Vendor", ToUserId = registerVendorResponse.Content.VendorId, CreatedDate = DateTime.Now }; await _loggingRepository.LogEmailTransaction(emailLogDetails); } else { postResponseModel.Success = registerVendorResponse.Success; } return(postResponseModel); }
public JsonResult Get(int pageIndex, int pageSize, string pageOrder, string to) { if (pageOrder.Trim() == "ID") { pageOrder = "LastUpdate desc"; } var list = EmailLogs.Get(pageIndex, pageSize, pageOrder, to); int total = EmailLogs.Count(to); int totalPage = (int)Math.Ceiling((decimal)total / pageSize); if (pageSize > total) { pageSize = total; } if (list.Count < pageSize) { pageSize = list.Count; } JsonResult result = new JsonResult() { Data = new { TotalPages = totalPage, PageIndex = pageIndex, PageSize = pageSize, Rows = list }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; return(result); }
public async Task <IHttpActionResult> GetApronApprovalChecklists(EmailLogs model) { var data = await Task.Run(() => Entities.SP_EmailReports(model.DateRange, model.Department)); return(Ok(data)); }
public async Task LogEmailTransaction(EmailLogs emailLogDetails) { await _databaseContext.Repository <EmailLogs>().AddAsync(emailLogDetails); _databaseContext.Commit(); }