I made a Razor MVC3 website, from which I can send E-Mails.
I made a service that gets all the users and emails information, and starts a thread that sends formatted emails.
I made my own threadpool.
On my computer everything work perfectly. I send emails every second.
But when I deploy my website on my Amazon server ec2, the email sending becomes so slow around (3min/mail) and fails half of my emails.
The amazon server is far more powerful than my computer. Same for the bandwidth.
I dont know if it is an IIS or a thread configuration than I missed.
Any ideas?
//—————– Code send email————————
using (SmtpClient smtp = new SmtpClient()
{
Host = serverSMTP,
Port = 25,
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(senderAddress.Address, carteiraPassword),
Timeout = 10000
})
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; //test
smtp.Send(message);
}
//—————–class thread————————
public class MyThread
{
#region Param
public string Id { get; set; }
public RunNewThread RunThreadDelegate;
private System.Threading.Thread Thread { get; set; }
#endregion
public SiscobThread(RunNewThread RunThreadDelegate)
{
this.RunThreadDelegate = RunThreadDelegate;
}
public void Init()
{
this.Thread = new System.Threading.Thread(this.RunThread);
MsgManager.Instance.SendError("Thread born " + this.Id, null);
}
private void RunThread()
{
this.RunThreadDelegate();
}
public void Start()
{
this.Thread.Start();
}
public void Stop()
{
this.Thread.Abort();
}
}
Check with Amazon. I’m pretty sure they throttle outbound email connections unless you fill out a form with them stating the purpose of the emails in your application.
This is there to make it a little more difficult for spammers to simply spin up new instances and broadcast their garbage.
I looked a little closer:
http://aws.amazon.com/ec2/faqs/#Are_there_any_limitations_in_sending_email_from_EC2_instances
Per Amazon: