Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.Mvc.Ajax;
- using OpenSkyMedia.Models;
- using System.Web.UI;
- using System.Net.Mail;
- namespace OpenSkyMedia.Controllers
- {
- public class EmailMeController : Controller
- {
- //
- // GET: /EmailMe/
- [AcceptVerbs(HttpVerbs.Post)]
- public ActionResult Index(EmailModel emailModel)
- {
- if (ModelState.IsValid)
- {
- bool isOk = false;
- try
- {
- MailMessage msg = new MailMessage();
- msg.From = new MailAddress("no-reply@bobcravens.com", "Website Contact Form");
- msg.To.Add("admin@openskymedia.com");
- 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("mailserver_url.net", 25);
- 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)
- {
- }
- // 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();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement