示例#1
0
        public async Task <ActionResult> BugReport(BugReportViewModel viewModel)
        {
            try
            {
                //SendGrid username and password from azure.
                var username = "******";
                var pswrd    = "27UICbH178dUI0m";
                //Create a new SendGrid message
                var mailMessage = new SendGridMessage();
                //Where the mail has to go to
                mailMessage.AddTo("*****@*****.**");
                //Sender from the mail
                mailMessage.From = new MailAddress(viewModel.EmailAddress);
                //Subject from the mail
                mailMessage.Subject = viewModel.Subject;
                //Body of the mail
                mailMessage.Html = viewModel.Message;
                mailMessage.Html = mailMessage.Html.Replace(Environment.NewLine, "<br />");
                var credentials = new NetworkCredential(username, pswrd);
                //Send the mail using SendGrid
                var transportWeb = new SendGrid.Web(credentials);
                await transportWeb.DeliverAsync(mailMessage);

                return(View());
            }
            catch (Exception ex)
            {
                Response.Write("Could not send the e-mail - error: " + ex.Message);
                return(View("~/Views/Shared/Error.cshtml"));
            }
        }
示例#2
0
 public async Task<ActionResult> BugReport(BugReportViewModel viewModel)
 {
     try
     {
         //SendGrid username and password from azure.
         var username = "******";
         var pswrd = "27UICbH178dUI0m";
         //Create a new SendGrid message
         var mailMessage = new SendGridMessage();
         //Where the mail has to go to
         mailMessage.AddTo("*****@*****.**");
         //Sender from the mail
         mailMessage.From = new MailAddress(viewModel.EmailAddress);
         //Subject from the mail
         mailMessage.Subject = viewModel.Subject;
         //Body of the mail
         mailMessage.Html = viewModel.Message;
         mailMessage.Html = mailMessage.Html.Replace(Environment.NewLine, "<br />");
         var credentials = new NetworkCredential(username, pswrd);
         //Send the mail using SendGrid
         var transportWeb = new SendGrid.Web(credentials);
         await transportWeb.DeliverAsync(mailMessage);
         return View();
     }
     catch (Exception ex)
     {
         Response.Write("Could not send the e-mail - error: " + ex.Message);
         return View("~/Views/Shared/Error.cshtml");
     }
 }