public void Send(SiteMessage siteMessage)
        {
            SendGridMessage sendGridMessage = new SendGridMessage();

            sendGridMessage.SetFrom(new EmailAddress(siteMessage.From));
            sendGridMessage.AddTo(siteMessage.To);
            sendGridMessage.SetSubject(siteMessage.Subject);

            sendGridMessage.AddContent(MimeType.Html, siteMessage.Body);


            if (ConfigurationManager.AppSettings["TestMode"] == "true")
            {
                System.IO.File.AppendAllText(ConfigurationManager.AppSettings["TestPath"] + "\\sentEmails.html",
                                             string.Format("{0}{1}{0}From:{2}{0}Subject:{3}{0}{4}{0}",
                                                           "<br/>", "-------------------------------", siteMessage.From, siteMessage.Subject, siteMessage.Body));
            }
            else
            {
                string apiKey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
                if (string.IsNullOrEmpty(apiKey))
                {
                    apiKey = ConfigurationManager.AppSettings["SENDGRID_APIKEY"];
                }
                SendGridClient client        = new SendGridClient(apiKey);
                Response       emailResponse = client.SendEmailAsync(sendGridMessage).Result;
            }
        }
        public void Send(SiteMessage siteMessage)
        {
            using (SmtpClient client = new SmtpClient())
            {
                MailMessage message = new MailMessage();

                message.From = new MailAddress(siteMessage.From);
                message.To.Add(new MailAddress(siteMessage.To));

                message.Subject = siteMessage.Subject;

                message.IsBodyHtml = true;
                message.Body       = siteMessage.Body;

                if (ConfigurationManager.AppSettings["TestMode"] == "true")
                {
                    System.IO.File.AppendAllText(ConfigurationManager.AppSettings["TestPath"] + "\\sentEmails.html",
                                                 string.Format("{0}{1}{0}From:{2}{0}Subject:{3}{0}{4}{0}",
                                                               "<br/>", "-------------------------------", siteMessage.From, siteMessage.Subject, siteMessage.Body));
                }
                else
                {
                    client.Send(message);
                }
            }
        }
        public void Send(ContactUs data)
        {
            ValidateInput(data);

            StringBuilder body = new StringBuilder();

            body.AppendFormat("<div>Name: {0}</div>", data.Name);
            body.AppendFormat("<div>Address: {0}</div>", data.Address);
            body.AppendFormat("<div>Town: {0}</div>", data.Town);
            body.AppendFormat("<div>Phone: {0}</div>", data.Phone);
            body.AppendFormat("<div>Email: {0}</div>", data.Email);
            body.AppendFormat("<div>Comments:</div><p>{0}</p>", data.Comments);

            SiteMessage siteMessage = new SiteMessage()
            {
                From    = data.Email,
                To      = ConfigurationManager.AppSettings["ContactUsEmailAddress"],
                Subject = ConfigurationManager.AppSettings["ContactUsEmailSubject"],
                Body    = body.ToString()
            };

            mailAdapter.Send(siteMessage);
        }