public ActionResult Log4Net(EmailMessage email) { string key = ConfigurationManager.AppSettings["Sendgrid.Key"]; SendGridService messageSvc = new SendGridService(key); string htmlBody = $@"<ul>From :{email.From}<li>To: {email.To}</li><li>Email: {email.Body}</li></ul>"; EmailMessage msg = new EmailMessage() { Body = htmlBody, Subject = "Winifred Osezuah", From = email.From, To = email.To }; string envPath = HttpRuntime.AppDomainAppPath; string fileName = $"{envPath}\\Log\\log-file.txt"; byte[] fileData = null; FileInfo fileInfo = new FileInfo(fileName); long imageFileLength = fileInfo.Length; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); fileData = br.ReadBytes((int)imageFileLength); messageSvc.SendMail(msg, true, fileName, fileData); return(RedirectToAction("Success", "LogError")); }
public async Task <int> Create(UserCreateRequest userCreateRequest) { int newId = 0; string passwordHash = BCrypt.Net.BCrypt.HashPassword(userCreateRequest.Password); try { dataProvider.ExecuteNonQuery( "User_Insert", (parameters) => { parameters.AddWithValue("@FirstName", userCreateRequest.FirstName); parameters.AddWithValue("@LastName", userCreateRequest.LastName); parameters.AddWithValue("@Email", userCreateRequest.Email); parameters.AddWithValue("@PasswordHash", passwordHash); parameters.AddWithValue("@MobilePhone", userCreateRequest.MobilePhone); parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output; }, (parameters) => { newId = (int)parameters["@Id"].Value; }); } catch (SqlException e) when(e.Number == 2601) { throw new DuplicateEmailException("Email already in use"); } Guid token = Guid.NewGuid(); dataProvider.ExecuteNonQuery( "Token_Insert", (parameters) => { parameters.AddWithValue("@Guid", token); parameters.AddWithValue("@Email", userCreateRequest.Email); parameters.AddWithValue("@TokenType", 1); }, (parameters) => { }); await sendGridService.SendMail(userCreateRequest.Email, userCreateRequest.FirstName, token); return(newId); }
public HttpResponseMessage SendEmail(EmailModel email) { try { if (!ModelState.IsValid) { return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "your fields are not valid")); } string key = ConfigurationManager.AppSettings["Sendgrid.Key"]; SendGridService messageSvc = new SendGridService(key); string htmlBody = $@"<ul>From :{email.From}<li>To: {email.To}</li><li>Email: {email.Body}</li></ul>"; EmailMessage msg = new EmailMessage() { Body = htmlBody, Subject = "Winifred Osezuah", From = email.From, To = email.To }; string envPath = HttpRuntime.AppDomainAppPath; string fileName = $"{envPath}\\Log\\log-file.txt"; byte[] fileData = null; FileInfo fileInfo = new FileInfo(fileName); long imageFileLength = fileInfo.Length; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); fileData = br.ReadBytes((int)imageFileLength); messageSvc.SendMail(msg, true, fileName, fileData); return(this.Request.CreateResponse(HttpStatusCode.OK, "Successfully sent mail")); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }