Advertisement
Guest User

Jason

a guest
Feb 8th, 2010
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Web.Mvc.Ajax;
  7. using OpenSkyMedia.Models;
  8. using System.Web.UI;
  9. using System.Net.Mail;
  10.  
  11. namespace OpenSkyMedia.Controllers
  12. {
  13.     public class EmailMeController : Controller
  14.     {
  15.         //
  16.         // GET: /EmailMe/
  17.  
  18.         [AcceptVerbs(HttpVerbs.Post)]
  19.         public ActionResult Index(EmailModel emailModel)
  20.         {
  21.             if (ModelState.IsValid)
  22.             {
  23.                 bool isOk = false;
  24.                 try
  25.                 {
  26.                     MailMessage msg = new MailMessage();
  27.                     msg.From = new MailAddress("no-reply@bobcravens.com", "Website Contact Form");
  28.                     msg.To.Add("admin@openskymedia.com");
  29.                     msg.Subject = emailModel.Subject;
  30.                     string body = "Name: " + emailModel.Name + "\n"
  31.                                 + "Email: " + emailModel.EmailAddress + "\n"
  32.                                 + "Website: " + emailModel.WebSite + "\n"
  33.                                 + "Phone: " + emailModel.Phone + "\n\n"
  34.                                 + emailModel.Message;
  35.  
  36.                     msg.Body = body;
  37.                     msg.IsBodyHtml = false;
  38.  
  39.                     SmtpClient smtp = new SmtpClient("mailserver_url.net", 25);
  40.  
  41.                     smtp.Send(msg);
  42.  
  43.                     msg.Dispose();
  44.  
  45.                     isOk = true;
  46.  
  47.                     MessageModel rcpt = new MessageModel();
  48.                     rcpt.Title = "Thank You";
  49.                     rcpt.Content = "Your email has been sent.";
  50.                     return View("Message", rcpt);
  51.                 }
  52.                 catch (Exception ex)
  53.                 {
  54.                 }
  55.  
  56.                 // If we are here...something kicked us into the exception.
  57.                 //
  58.                 MessageModel err = new MessageModel();
  59.                 err.Title = "Email Error";
  60.                 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.";
  61.                 return View("Message", err);
  62.             }
  63.             else
  64.             {
  65.                 return View();
  66.             }
  67.         }
  68.  
  69.  
  70.     }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement