Exemplo n.º 1
0
        public void SendEmail(EmailModel email)
        {
            email.ToEmail = Config.Current.EmailDeveloper.Address;
            email.ToName = Config.Current.EmailDeveloper.DisplayName;
            email.Subject = string.Format("[Web] " + email.Subject);

            var body = PreMailer.Net.PreMailer.MoveCssInline(email.Message, false);
            email.Message = body.Html;

            var replyToAddress = GetReplyToAddress(email.ReplyToAddress);

            using (var message = new MailMessage())
            {
                message.From = new MailAddress(email.FromEmail, email.FromName);

                message.ReplyToList.Add(replyToAddress);

                message.To.Add(new MailAddress(email.ToEmail, email.ToName));
                message.Subject = email.Subject;
                message.IsBodyHtml = true;
                message.Body = email.Message;
                using (var client = new SmtpClient())
                {
                    client.Send(message);
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Index(EmailModel m)
        {
            if (TryValidateModel(m) && !m.IsSpam)
            {
                var email = new EmailModel();

                email.FromEmail = Config.Current.EmailNoReply.Address;
                email.FromName = m.FromName;
                email.Subject = m.Subject;
                email.Message = m.Message;
                try
                {
                    var mailAddr = new MailAddress(m.FromEmail);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("FromEmail", "Please input valid email address");
                    return View(m);
                }

                email.ReplyToAddress = m.FromEmail;

                var emailService = new EmailService();
                emailService.SendEmail(email);

                return View("EmailSent");
            }
            return View(m);
        }
Exemplo n.º 3
0
        public ActionResult Index(ReferFriendModel m)
        {
            if(TryValidateModel(m) && !m.IsSpam)
            {
                var email = new EmailModel();

                email.FromEmail = Config.Current.EmailNoReply.Address;
                email.FromName = m.Name;
                email.Subject = "Refer a friend";
                email.Message = "Friend's name: " + m.FriendName + ",<br /> Friend's phone number: " + m.Phone + "<br /> My name: " + m.Name ;
                email.ReplyToAddress = email.FromEmail;

                var emailService = new EmailService();
                emailService.SendEmail(email);
                return View("Submitted");
            }
            return View(m);
        }