コード例 #1
0
ファイル: EmailService.cs プロジェクト: stu-millner/AudioText
        public static async Task<bool> SendMessageToCustomer(ContactModel model)
        {
            return await Task.Run(async () =>
            {
                MailMessage email = new MailMessage();
                email.Body = model.Message;
                email.Subject = model.Subject;


                try
                {
                    var section = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
                    email.To.Add(model.Email);

                    using (var smtp = new SmtpClient())
                    {
                        await smtp.SendMailAsync(email);
                        return true;
                    }
                }
                catch (Exception exception)
                {
                    return false;

                }
            });
        }
コード例 #2
0
ファイル: EmailService.cs プロジェクト: stu-millner/AudioText
        public static async Task<bool> SendMessageFromCustomer(ContactModel model)
        {
            return await Task.Run(async () =>
             {
                 MailMessage email = new MailMessage();


                 email.Body = String.Format("Message: {0} \n\nRespond To: {1}", model.Message, model.Email);
                 email.Subject = string.Format("{0} -- {1} {2}", model.Subject, model.FirstName, model.LastName);

                 try
                 {
                     var section = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
                     email.To.Add(section.Network.UserName);

                     using (var smtp = new SmtpClient())
                     {
                         await smtp.SendMailAsync(email);
                         return true;
                     }
                 }
                 catch (Exception exception)
                 {
                     return false;

                 }
             });

        }
コード例 #3
0
        public async Task<ActionResult> sendContactEmail(ContactModel model)
        {
            bool sentSuccessfully = await EmailService.SendMessageFromCustomer(model);
            if (sentSuccessfully)
            {
                return View("_resultPage", new ResultViewModel("Thank you for your feedback", 
                    String.Format("Thank you {0} for getting in contact with us. We appreciate what you have to say.", model.FirstName)));
            }
            else
            {
                return View("_resultPage", new ResultViewModel("Something went wrong while trying to send your message.",
                    "We apologize for the inconvenience. We still want to hear from you, try sending an independent e-mail or try again at later."));
            }

        }