public void SendEmail(RequistionDTO requistion, string userId) { DateTime createdOn = DateTime.Now; StringBuilder sb = new StringBuilder(); string strNewPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["RequistionEmail"]); using (StreamReader sr = new StreamReader(strNewPath)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } string body = sb.ToString().Replace("#REQUISTIONNUMBER#", requistion.RequistionNumber); body = body.Replace("#DESCRIPTION#", requistion.Description); body = body.Replace("#CREATEDBY#", userId); body = body.Replace("#CREATEDON#", Convert.ToString(createdOn)); Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = ConfigurationManager.AppSettings["administrator-email"]; email.MailFromAddress = ConfigurationManager.AppSettings["EmailAddressFrom"]; email.Subject = ConfigurationManager.AppSettings["requistion_email_subject"]; email.SendMail(); logger.Debug("Email sent"); }
public JsonResult EmailValidation(string id, string id2) { var apiNumber = id2; if (User.Identity.IsAuthenticated) { var helper = new Helpers.CreditsDeduct(); var res = helper.IsValid(User.Identity.Name, 6, id, "single", "email"); if (res == false) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(404, JsonRequestBehavior.AllowGet); } } else { var isValid = new IsValid(); bool tUser = isValid.ValidUser(apiNumber, id, "email"); if (tUser == false) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(410, JsonRequestBehavior.AllowGet); } } var tmpResilts = new Helpers.Email(); var tmpResult = tmpResilts.Validate(id); return Json(tmpResult, JsonRequestBehavior.AllowGet); }
public void SendWelcomeEmail(string emailAddress, string firstName) { StringBuilder sb = new StringBuilder(); string strNewPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["welcomeEmail"]); using (StreamReader sr = new StreamReader(strNewPath)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } string body = sb.ToString().Replace("#FIRSTNAME#", firstName); body = body.Replace("#YOUREMAIL#", emailAddress); Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = emailAddress; email.MailFromAddress = ConfigurationManager.AppSettings["no-reply-email"]; email.Subject = ConfigurationManager.AppSettings["welcome_email_subject"]; email.SendMail(); logger.Debug("Email sent"); }
public IHttpActionResult Post([FromBody] Usuario usuario) { try { if (!ModelState.IsValid) { return(BadRequest("Verificar campos obrigatórios")); } if (_repository.EmailExists(usuario.Email)) { return(BadRequest("E-mail já utilizado por outro usuário")); } _repository.Insert(usuario); if (usuario.NotificarUsuario) { string body = @" <html> <head> <title></title> </head> <body> <p><img src='{0}' width='200' /></p> <p>Olá, <strong>{1}</strong>. Seja Bem Vindo(a)!</p> <p>Você está cadastrad(a) na Central de Ativos e já pode acessar o sistema.</p> <p>Para isso, acesse o link abaixo e cadastre sua senha.</p> <p><a href='{2}'>Clique Aqui</a></p> <p>Em caso de dúvidas, entre em contato conosco.</p> <p><strong>Equipe Saraf</strong></p> </body> </html> "; body = string.Format(body, System.Configuration.ConfigurationManager.AppSettings["urlBaseWeb"] + "content/img/logo.png", usuario.Nome, System.Configuration.ConfigurationManager.AppSettings["urlBaseWeb"] + "home/primeiroacesso"); var email = new Helpers.Email(usuario.Email, "Central de Ativos - Seja Bem Vindo", body, true, "Central de Ativos", usuario.Nome); email.Enviar(); } return(Ok(usuario)); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult NotificarPrimeiroAcesso(int usuarioID) { try { var usuario = _repository.GetByID(usuarioID); if (usuario == null) { return(NotFound()); } if (!usuario.PrimeiroAcesso) { return(BadRequest("O usuário informado já acessou o sistema, não é possível notificar Primeiro Acesso")); } string body = @" <html> <head> <title></title> </head> <body> <p><img src='{0}' width='200' /></p> <p>Olá, <strong>{1}</strong>. Seja Bem Vindo(a)!</p> <p>Você está cadastrado(a) na Central de Ativos e já pode acessar o sistema.</p> <p>Para isso, acesse o link abaixo e cadastre sua senha.</p> <p><a href='{2}'>Clique Aqui</a></p> <p>Em caso de dúvidas, entre em contato conosco.</p> <p><strong>Equipe Saraf</strong></p> </body> </html> "; body = string.Format(body, System.Configuration.ConfigurationManager.AppSettings["urlBaseWeb"] + "content/img/logo.png", usuario.Nome, System.Configuration.ConfigurationManager.AppSettings["urlBaseWeb"] + "home/primeiroacesso"); var email = new Helpers.Email(usuario.Email, "Central de Ativos - Seja Bem Vindo", body, true, "Central de Ativos", usuario.Nome); email.Enviar(); return(Ok()); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult SolicitarRecadastramentoSenha([FromBody] Usuario usuario) { try { usuario = _repository.GetAll().Where(x => x.Email.ToLower() == usuario.Email.ToLower() && x.DataExclusao == null).SingleOrDefault(); if (usuario == null) { return(NotFound()); } usuario.TokenSolicitacaoSenha = Guid.NewGuid(); usuario.DataValidadeTokenSenha = DateTime.Now.AddDays(1); usuario.Perfil = null; usuario.ConfirmacaoSenha = usuario.Senha; _repository.Update(usuario); string body = @" <html> <head> <title></title> </head> <body> <p><img src='{0}' width='200' /></p> <p>Olá, {1}!</p> <p>Para recadastrar sua senha, clique no link abaixo:</p> <p><a href='{2}'>Clique Aqui</a></p> <p><strong>Equipe Saraf</strong></p> </body> </html> "; body = string.Format(body, System.Configuration.ConfigurationManager.AppSettings["urlBaseWeb"] + "content/img/logo.png", usuario.Nome, System.Configuration.ConfigurationManager.AppSettings["urlBaseWeb"] + "usuario/recadastrarsenha/" + usuario.TokenSolicitacaoSenha); var email = new Helpers.Email(usuario.Email, "Central de Ativos - Recadastramento de Senha", body, true, "Central de Ativos", usuario.Nome); email.Enviar(); return(Ok(usuario)); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }
public void SendProductSellerEmailNotificationWhenBiddingEnds(string body, string emailAddress) { Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = emailAddress; email.MailFromAddress = ConfigurationManager.AppSettings["EmailAddressFrom"]; email.Subject = "BIDDING FOR YOUR PRODUCT HAS ENDED"; try { email.SendMail(); } catch (Exception ex) { } }
//Send off query as email public void SendEmail(WebQueryDTO query) { StringBuilder sb = new StringBuilder(); string strNewPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["QueryAsEmail"]); using (StreamReader sr = new StreamReader(strNewPath)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } string body = sb.ToString().Replace("#NAME#", query.Name); body = body.Replace("#PHONE#", query.PhoneNumber); body = body.Replace("#QUERY#", query.Body); body = body.Replace("#EMAIL#", query.EmailAddress); Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = ConfigurationManager.AppSettings["EmailAddressTo"]; email.MailFromAddress = ConfigurationManager.AppSettings["no-reply-email"]; email.Subject = ConfigurationManager.AppSettings["query_email_subject"]; try { email.SendMail(); logger.Debug("Email sent"); } catch (Exception ex) { logger.Debug("email Not Sent: " + ex.Message); } }
public void SendForgotPasswordEmail(string emailAddress, string firstName, string callBackUrl) { StringBuilder sb = new StringBuilder(); string strNewPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["forgotPasswordEmail"]); using (StreamReader sr = new StreamReader(strNewPath)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } string body = sb.ToString().Replace("#FIRSTNAME#", firstName); body = body.Replace("#CALLBACKURL#", callBackUrl); Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = emailAddress; email.MailFromAddress = ConfigurationManager.AppSettings["EmailAddressFrom"]; email.Subject = ConfigurationManager.AppSettings["forgotPassword_email_subject"]; try { email.SendMail(); logger.Debug("Email sent"); } catch (Exception ex) { //Response.Write(ex.Message.ToString()); logger.Debug("Email has not been sent"); } }
//Send off comment as email public void SendCommentEmailToAdmin(CommentDTO query, string userName) { StringBuilder sb = new StringBuilder(); string strNewPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["CommentAsEmail"]); using (StreamReader sr = new StreamReader(strNewPath)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } string body = sb.ToString().Replace("#MEDIAID#", Convert.ToString(query.MediaId)); body = body.Replace("#BODY#", query.Body); body = body.Replace("#USER#", userName); Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = ConfigurationManager.AppSettings["EmailAddressTo"]; email.MailFromAddress = ConfigurationManager.AppSettings["no-reply-email"]; email.Subject = ConfigurationManager.AppSettings["comment_email_subject"]; try { email.SendMail(); logger.Debug("Email sent"); } catch (Exception ex) { logger.Debug("email Not Sent: " + ex.Message); } }
public ActionResult BulkEmailValidation(IEnumerable<HttpPostedFileBase> fileToUpload) { var outputStream = new MemoryStream(); int i = 0; int validEmails = 0; int invalidEmails = 0; int sintacsisValid = 0; int recordsSubmited = 0; using (var zip = new ZipFile()) { string time = User.Identity.Name + DateTime.Now.Ticks; Directory.CreateDirectory(Server.MapPath("~/Tuploads/") + time); string folder = Server.MapPath("~/Tuploads/") + time + "/"; foreach (var csvFile in fileToUpload) { var results = new List<EmailValidationViewModel>(); if (csvFile.ContentType.ToString() != "application/vnd.ms-excel") { results.Add(new EmailValidationViewModel { Message = "Wrong file type! File must be CSV" }); return Json(results, JsonRequestBehavior.AllowGet); } string targetFolder = folder + csvFile.FileName; csvFile.SaveAs(targetFolder); var csvToData = new CsvToDataTable(); var csvData = csvToData.GetDataTabletFromCSVFile(targetFolder, "email"); //Billing int records = csvData.Rows.Count; recordsSubmited += records; if (User.Identity.IsAuthenticated) { var helper = new Helpers.CreditsDeduct(); var res = helper.IsValid(User.Identity.Name, records, "", "bulk", "email"); if (res == false) { results.Add(new EmailValidationViewModel { Message = "You don't have enought credits left. Please Top Up!" }); return Json(results, JsonRequestBehavior.AllowGet); } } foreach (DataRow res in csvData.Rows) { foreach (var item in res.ItemArray) { var tmpResilts = new Helpers.Email(); var tmpResult = tmpResilts.Validate(item.ToString()); foreach (var tt in tmpResult) { results.Add(new EmailValidationViewModel { Email = tt.Email, IsValid = tt.IsValid, Message = tt.Message, MxRecord = tt.MxRecord }); if (tt.IsValid == "Yes") validEmails++; else if (tt.IsValid == "") invalidEmails++; else sintacsisValid++; } } } this.Data.EmailCleansingHistory.Add(new EmailCleansingHistory { DateSubmited = DateTime.Now, InvalidEmail = invalidEmails, RecordsUploaded = recordsSubmited, SyntaxValid = sintacsisValid, UserName = User.Identity.Name, ValidEmail = validEmails }); this.Data.SaveChanges(); MemoryStream output = new MemoryStream(); if (results.Count() > 0) { StreamWriter writer = new StreamWriter(output, Encoding.UTF8); StringBuilder sb = new StringBuilder(); writer.Write("Email address, Mx Record, Is valid, Message "); writer.Write(Environment.NewLine); foreach (var details in results) { sb.Append(details.Email + "," + details.MxRecord + "," + details.IsValid + "," + details.Message); writer.Write(sb); writer.Write(Environment.NewLine); sb.Clear(); } writer.Flush(); output.Position = 0; } //If any records write them to csv file and return to user if (fileToUpload.Count() == 1) { return File(output, "text/coma-separated-values", User.Identity.Name + "_" + DateTime.Now.Ticks + ".csv"); } else { using (FileStream file = new FileStream(folder + "test" + i + ".csv", FileMode.Create, System.IO.FileAccess.Write)) { byte[] bytes = new byte[output.Length]; output.Read(bytes, 0, (int)output.Length); file.Write(bytes, 0, bytes.Length); output.Close(); } zip.AddFile(folder + "test" + i + ".csv", @"\"); i++; if (i == fileToUpload.Count()) { zip.Save(outputStream); } } } outputStream.Position = 0; outputStream.Seek(0, SeekOrigin.Begin); return File(outputStream, "application/octet-stream", "filename.zip"); } }