As I am moving many of my websites onto my own amazon ec2 servers, one of the issues I am facing is how to send emails from my ASP.NET apps. I spend quite some time trying to configure the Windows Server 2008 SMTP servers (not an easy job) and then learned that actually sending mail from the Amazon IP addresses will get red flag as bad email and most likely get caught in spam filters. So here is what you can do: use googles (gmail) SMTP server, link it to you domain's email address through the gmail process, and then use the following C# class to send your mail:
using System;
using System.Net.Mail;
using System.Net;
namespace KS.Util
{
public class postMaster
{
//address
public string emailTo;
public string emailFrom;
//message
public string subject;
public string message;
public bool isHtml = false;
//login
public string login;
public string password;
public string smtpServer;
//system
public bool isSuccessful = false;
public string errorMessage = "sucess";
public void send()
{
try
{
NetworkCredential loginInfo = new NetworkCredential(login, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(emailFrom);
msg.To.Add(new MailAddress(emailTo));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = isHtml;
SmtpClient client = new SmtpClient(smtpServer);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Port = 587;
client.EnableSsl = true;
client.Send(msg);
isSuccessful = true;
}
catch (Exception ex)
{
errorMessage = ex.Message.ToString();
}
}
}
}
Here is how you use it:
NS.Util.postMaster pm = New NS.Util.postMaster()
pm.emailTo = strName + " <" + strEmail + ">";
pm.emailFrom = "post master ";
pm.subject = EmialSubject;
pm.message = EmialBody;
pm.isHtml = True;
pm.login = "YourEmail@gmail.com";
pm.password = "password";
pm.smtpServer = "smtp.gmail.com";
pm.send();