Reputation: 282
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();
}
}
Upvotes: 1
Views: 286
Reputation: 282
thanks it was this. I receive at the end of the day:
Dear EC2 Customer, You recently reached a limit on the volume of email you were able to send out of SMTP port 25 on your instance:
Instance ID: xxxxxxxx * IP Address: xxxxxxxx * Start date: xxxxxxxx
In order to maintain the quality of EC2 addresses for sending email, we enforce default limits on the amount of email that can be sent from EC2 accounts. If you wish to send larger amounts of email from EC2, you can apply to have these limits removed from your account by filling out our online request form.
If you are unaware of your instance having sent emails, we advise checking your instance application(s) to confirm that this activity was intended. It is your responsibility to ensure that your instances and all applications are secured against unauthorized use. For suggestions on securing your instances, visit aws.amazon.com/security.
Regards, Your Amazon Web Services EC2 team
Upvotes: 0
Reputation: 88072
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:
Yes. In order to maintain the quality of EC2 addresses for sending email, we enforce default limits on the amount of email that can be sent from EC2 accounts. If you wish to send larger amounts of email from EC2, you can apply to have these limits removed from your account by filling out this form.
Upvotes: 3