Пример #1
0
        public HttpResponseMessage NlogEmailSender(EmailViewModel emvm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.BadRequest, "Your fields are not valid"));
                }
                string key = ConfigurationManager.AppSettings["Sendgrid.Key"];

                EmailService service = new EmailService(key);

                EmailMessage msg = EmailMessage.CreateMessage(emvm.Email, emvm.Subject, emvm.Message);

                var fileName = FileToByteArrayConverter.GetFilePath("logs\\2018-05-21.log");
                var fileData = FileToByteArrayConverter.Convert(fileName);

                service.SendMail(msg, false, fileName, fileData);

                return(this.Request.CreateResponse(HttpStatusCode.OK, "Mail successfully sent"));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        private void RealizarEnvio(EmailMessage message, Factura factura)
        {
            var mimeMessage = message.CreateMessage(message);

            using (SmtpClient smtpClient = new SmtpClient())
            {
                smtpClient.Connect(_mailData.SmtpServer,
                                   _mailData.Port, true);
                smtpClient.Authenticate(_mailData.UserName,
                                        _mailData.Password);
                smtpClient.Send(mimeMessage);
                smtpClient.Disconnect(true);
            }
            _facturaService.Update(factura.Id, factura);
        }
Пример #3
0
        private static async Task EmailSender(RegisterBindingModel model)
        {
            string       key        = ConfigurationManager.AppSettings["Key.Sendgrid"];
            EmailService messageSvc = new EmailService(key);

            string htmlBody = $@"<h3>Welcome to Job Seeker Webpage</h3>
                                    <p>The following are your credentials: keep it safe</p>
                                 <ul> 
                                <li>Email: {model.Email}</li>
                                <li>Phone Number: {model.PhoneNumber}</li>
                            </ul>";

            EmailMessage msg = EmailMessage.CreateMessage(model.Email, "Registeration Successful", htmlBody);

            await messageSvc.SendMail(msg, true);
        }