The solution to the problem was this. I ended up using winhosts SMTP. My email is hosted is hosted on google. I couldn't send to an email address that was of the same domain as my hosting company though because it looked there first for the email address. When it didn't find it it errored out. I instead, had to have the email sent to my gmail account which then forwarded to my openskymedia address based upon return address and some certain text in the email. It's a little convoluted but it worked. The code below was able to work for me to send email from the form and works pretty nicely.
public ActionResult Index(EmailModel emailModel)
{
if (ModelState.IsValid)
{
bool isOk = false;
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]", "Website Contact Form");
msg.To.Add("[email protected]");
msg.Subject = emailModel.Subject;
string body = "Name: " + emailModel.Name + "\n"
+ "Email: " + emailModel.EmailAddress + "\n"
+ "Website: " + emailModel.WebSite + "\n"
+ "Phone: " + emailModel.Phone + "\n\n"
+ emailModel.Message;
msg.Body = body;
msg.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient("your.server.com");
NetworkCredential Credentials = new NetworkCredential("[email protected]", "password");
smtp.Credentials = Credentials;
smtp.Send(msg);
msg.Dispose();
isOk = true;
MessageModel rcpt = new MessageModel();
rcpt.Title = "Thank You";
rcpt.Content = "Your email has been sent.";
return View("Message", rcpt);
}
catch (Exception ex)
{
//while (ex != null)
//{
// Response.Write("<HR>" + ex.ToString());
// ex = ex.InnerException;
//}
}
// If we are here...something kicked us into the exception.
//
MessageModel err = new MessageModel();
err.Title = "Email Error";
err.Content = "The website is having an issue with sending email at this time. Sorry for the inconvenience. My email address is provided on the about page.";
return View("Message", err);
}
else
{
return View();
}
}