public IHttpActionResult SendEmailToActivity(string id, string session, [FromBody] EmailContentViewModel email)
        {
            if (!ModelState.IsValid || string.IsNullOrWhiteSpace(id))
            {
                string errors = "";
                foreach (var modelstate in ModelState.Values)
                {
                    foreach (var error in modelstate.Errors)
                    {
                        errors += "|" + error.ErrorMessage + "|" + error.Exception;
                    }
                }
                throw new BadInputException()
                      {
                          ExceptionMessage = errors
                      };
            }
            _emailService.SendEmailToActivity(id, session, email.FromAddress, email.Subject, email.Content, email.Password);

            //if (result == null)
            //{
            //    NotFound();
            //}
            //return Ok(result);
            return(Ok());
        }
        public EmailContent(EmailModel email)
        {
            InitializeComponent();

            _email           = new EmailContentViewModel(email);
            this.DataContext = _email.Email;
        }
Beispiel #3
0
        public EmailContentViewModel Create(string toAddress, string fromAddress, string subject, string body)
        {
            var result = new EmailContentViewModel
            {
                Content = body,
                To      = toAddress,
                From    = fromAddress,
                Subject = subject
            };

            return(result);
        }
Beispiel #4
0
        public ActionResult Index(EmailContentViewModel model)
        {
            var result = new SendEmailResult();

            try
            {
                _emailService.Send(model);

                result.Result = "Email sent!";
            }
            catch (Exception e)
            {
                result.Result = $"Email failed to send: {e.Message}";
            }

            TempData["result"] = result;

            return(RedirectToAction("EmailResult"));
        }
        public IHttpActionResult SendEmails([FromBody] EmailContentViewModel email)
        {
            if (!ModelState.IsValid)
            {
                string errors = "";
                foreach (var modelstate in ModelState.Values)
                {
                    foreach (var error in modelstate.Errors)
                    {
                        errors += "|" + error.ErrorMessage + "|" + error.Exception;
                    }
                }
                throw new BadInputException()
                      {
                          ExceptionMessage = errors
                      };
            }
            var to_emails = email.ToAddress.Split(',');

            _emailService.SendEmails(to_emails, email.FromAddress, email.Subject, email.Content, email.Password);
            return(Ok());
        }
Beispiel #6
0
        public static void SendEmailMsg(EmailContentViewModel MailContents)
        {
            // Create the email object first, then add the properties.
            SendGridMessage myMessage = new SendGridMessage();

            myMessage.AddTo(MailContents.EmailToStr.Split(',').ToList());

            if (MailContents.EmailCcStr != null && MailContents.EmailCcStr != "")
            {
                foreach (var item in MailContents.EmailCcStr.Split(','))
                {
                    myMessage.AddCc(item);
                }
            }

            if (MailContents.EmailBCcStr != null && MailContents.EmailBCcStr != "")
            {
                foreach (var item in MailContents.EmailBCcStr.Split(','))
                {
                    myMessage.AddBcc(item);
                }
            }


            myMessage.Subject = MailContents.EmailSubject;
            myMessage.Html    = MailContents.EmailBody;

            string username      = ConfigurationManager.AppSettings["MailAccount"];
            string password      = ConfigurationManager.AppSettings["Mailpassword"];
            string FromEmail     = MailContents.EmailUser;
            string FromEmailName = MailContents.EmailUserName;

            myMessage.From = new MailAddress(FromEmail, FromEmailName);

            if (!string.IsNullOrEmpty(MailContents.FileNameList))
            {
                foreach (string item in MailContents.FileNameList.Split(',').ToList())
                {
                    myMessage.AddAttachment(item);
                }
            }


            // Create credentials, specifying your user name and password.
            var credentials = new NetworkCredential(username, password);

            // Create an Web transport for sending email.
            var transportWeb = new Web(credentials);

            // Send the email.
            // You can also use the **DeliverAsync** method, which returns an awaitable task.
            try
            {
                // Send the email.
                if (transportWeb != null)
                {
                    transportWeb.DeliverAsync(myMessage);
                }
                else
                {
                    Trace.TraceError("Failed to create Web transport.");
                    Task.FromResult(0);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message + " SendGrid probably not configured correctly.");
            }
        }
Beispiel #7
0
        public void Send(EmailContentViewModel content)
        {
            var mailMessage = new MailMessage(content.From, content.To, content.Subject, content.Content);

            _smtpClientWrapper.Send(mailMessage);
        }