简体   繁体   English

慢线程电子邮件发件人

[英]Slow thread Email Sender

I made a Razor MVC3 website, from which I can send E-Mails. 我创建了一个Razor MVC3网站,我可以从中发送电子邮件。

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. 但是当我在我的亚马逊服务器ec2上部署我的网站时,电子邮件发送变得如此缓慢(3分钟/邮件)并且失败了一半的电子邮件。

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. 我不知道它是IIS还是线程配置,而不是我错过了。

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 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. 为了保持用于发送电子邮件的EC2地址的质量,我们对可以从EC2帐户发送的电子邮件数量实施默认限制。 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 . 如果您希望从EC2发送大量电子邮件,您可以通过填写此表单申请从您的帐户中删除这些限制。

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: 亲爱的EC2客户,您最近达到了您可以从实例上的SMTP端口25发送的电子邮件数量限制:

Instance ID: xxxxxxxx * IP Address: xxxxxxxx * Start date: xxxxxxxx 实例ID:xxxxxxxx * IP地址:xxxxxxxx *开始日期: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. 为了保持用于发送电子邮件的EC2地址的质量,我们对可以从EC2帐户发送的电子邮件数量实施默认限制。 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. 如果您希望从EC2发送大量电子邮件,您可以填写我们的在线申请表,申请从您的帐户中删除这些限制。

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. 有关保护实例的建议,请访问aws.amazon.com/security。

Regards, Your Amazon Web Services EC2 team 此致,您的Amazon Web Services EC2团队

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM