Permalink
Browse files

updated email sending service

  • Loading branch information...
1 parent 6e101ea commit 478302def386e9263e8ed10b56664e93e63cfa05 @nberardi nberardi committed Oct 9, 2012
Showing with 15 additions and 14 deletions.
  1. +15 −3 App_Code/SendEmailHandler.cs
  2. +0 −11 Web.config
@@ -19,10 +19,23 @@ public void ProcessRequest(HttpContext context)
context.Response.Redirect(HttpStatusCode.Found, "http://spammerbegone.com");
else {
using (MailMessage message = new MailMessage())
+ using (SmtpClient smtp = new SmtpClient())
{
+ string smtpHost = WebConfigurationManager.AppSettings["Smtp:Host"];
+ int smtpPort = Convert.ToInt32(WebConfigurationManager.AppSettings["Smtp:Port"]);
+ string smtpUsername = WebConfigurationManager.AppSettings["Smtp:Username"];
+ string smtpPassword = WebConfigurationManager.AppSettings["Smtp:Password"];
+
+ var creds = new NetworkCredential(smtpUsername, smtpPassword);
+ var auth = creds.GetCredential(smtpHost, smtpPort, "Basic");
+
+ smtp.Host = smtpHost;
+ smtp.Port = smtpPort;
+ smtp.Credentials = auth;
+
string contactName = context.Request.Form["contact-name"];
string contactEmail = context.Request.Form["contact-email"];
-
+
message.To.Add(new MailAddress(WebConfigurationManager.AppSettings["InfoEmail"], "Managed Fusion"));
message.To.Add(new MailAddress(contactEmail, contactName));
message.From = new MailAddress(WebConfigurationManager.AppSettings["NoReplyEmail"], "Managed Fusion No Reply");
@@ -35,8 +48,7 @@ public void ProcessRequest(HttpContext context)
foreach (string id in context.Request.Form.AllKeys)
message.Body += id + ":" + Environment.NewLine + context.Request.Form[id] + Environment.NewLine + Environment.NewLine;
-
- SmtpClient smtp = new SmtpClient();
+
smtp.Send(message);
}
View
@@ -27,17 +27,6 @@
</customErrors>
</system.web>
-
- <system.net>
- <mailSettings>
- <smtp deliveryMethod="Network">
- <network host="localhost" />
- </smtp>
- </mailSettings>
- <!-- defaultProxy>
- <proxy proxyaddress="http://127.0.0.1:8888" />
- </defaultProxy -->
- </system.net>
<system.webServer>
<handlers>

0 comments on commit 478302d

Please sign in to comment.