I use GoDaddy for my Windows Hosting. It’s affordable, supports ASP.Net 4.0 with MVC3, and supports multiple domains and SQL servers. The first issue I ran into was sending mail in code which is a little different than other Windows hosting providers. Here is what I did to get it to work perfectly without needing an actual email account with GoDaddy.
First I created a folder in my MVC3 project named Helpers and added a class called Email.cs with the following code.
public class Email
{
internal static void SendEmail(string fromAddress, string subject, string body)
{
var fAddress = new MailAddress("anything@yourdomain.com");
var tAddress = new MailAddress("anything@yourdomain.com");
var message = new MailMessage(fAddress, tAddress)
{
Subject = subject + " From " + fromAddress,
Body = body
};
var client = new SmtpClient("relay-hosting.secureserver.net");
client.Send(message);
}
}Then I created a Model in my Model folder called ContactModel.cs with the following code.
public class ContactModel
{
[Required]
[RegularExpression(@"^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$")]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email Address")]
public string EmailAddress { get; set; }
[Required]
[Display(Name = "Message")]
public string UserMessage { get; set; }
}Then I created a ActionResult in my Home controller although you can create a whole separate controller if you wish works either way. Here is the ActionResult code. ContactSuccess is just a page that says it works.
public ActionResult Contact()
{
return View();
}
[HttpPost]
public ActionResult Contact(ContactModel model)
{
if (ModelState.IsValid)
{
Email.SendEmail(model.EmailAddress, "Website Contact", model.UserMessage);
return Redirect("ContactSuccess");
}
else
{
ModelState.AddModelError("", "All fields are required.");
}
return View(model);
}
public ActionResult ContactSuccess()
{
return View();
}Here is the code in my View file for the actual contact form Contact.chtml.
@model ProjectName.Models.ContactModel
@{
ViewBag.Title = "Contact Us";
}
<h2>Contact Us</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate-vsdoc.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<p><strong>@Html.LabelFor(m => m.EmailAddress)</strong><br/>
@Html.TextBoxFor(m => m.EmailAddress)
@Html.ValidationMessageFor(m => m.EmailAddress, "*")</p>
<p><strong>@Html.LabelFor(m => m.UserMessage)</strong><br/>
@Html.TextAreaFor(m => m.UserMessage)
@Html.ValidationMessageFor(m => m.UserMessage, "*")</p>
<p><input type="submit" value="Send" /></p>
}Not to sell out because I actually like GoDaddy’s Windows Hosting you can get a discounted price and help me pay my bills by clicking Here. ![]()


