简体   繁体   English

处置后,SMTP连接需要时间才能连接

[英]SMTP Connection takes time to connect after Dispose

I have an issue with an App i made to send out Emails in Bulk. 我制作的用于批量发送电子邮件的应用程序存在问题。 The steps which are taken are described below: 采取的步骤如下所述:

  • First, the SMTP connection is made (anonymous access is used) 首先,建立SMTP连接(使用匿名访问)
  • The app sends out 10 emails per batch (10 is the limit the SMTP accepts for each connection) 该应用程序每批发送10封电子邮件(10封SMTP接受每个连接的限制)
  • When 10 emails are reached, the SMTP session is disposed and new one is created. 当到达10封电子邮件时,将丢弃SMTP会话并创建新的SMTP会话。

The problem i am facing is that after 3rd batch, i start to face alot of Time out issues from the SMTP(ie the app either says timeout Or Failure to sent email) and this goes out till the end and there are about 20 to 30 failures out of 221 emails. 我面临的问题是,在第三批处理之后,我开始面临来自SMTP的大量超时问题(即应用程序显示超时或无法发送电子邮件),这种情况一直持续到最后,大约有20到30 221封电子邮件中失败。

Below is the code i have written for this: 下面是我为此编写的代码:

      Try

        'create the mail message
        Dim mail As New MailMessage()

        'set the addresses

        mail.From = New MailAddress("noreply@nasmiles.flynas.com")


        If (ConfigurationManager.AppSettings("Setup").Equals("Testing")) Then
            mail.[To].Add("Retroflynas@gmail.com")
            'mail.[To].Add("ironhide707@gmail.com")
        Else
            mail.[To].Add(recepient)
            mail.[Bcc].Add("Retroflynas@gmail.com")
        End If

        'set the content

        mail.Subject = subject

        mail.Body = body


        smtp.Port = 25



        'send the message


        objWriter.WriteLine("Case No: " + CaseNo + "From: " + mail.From.ToString + "           " + "To: " + mail.To.ToString + "       " + "subject: " + mail.Subject.ToString + "  Email Sent")
        Console.WriteLine("Email Sent to the address: " + recepient)

        ' Update handback email column
        Updatehandback(CaseNo, "Yes")


        mailcount = mailcount + 1

    Catch ex As Exception
        ex.StackTrace.ToString()
        'objWriter.WriteLine(ex.Message.ToString + " " + ex.InnerException.ToString)
        objWriter.WriteLine(ex.Message.ToString)
        objWriter.WriteLine("Case No: " + CaseNo + "  Email Not Sents")
        ' Update handback email column
        Updatehandback(CaseNo, "No")
    End Try



    ' Check to see if mail count has reached 9 
    If (mailcount = 9) Then
        Console.WriteLine("***************MailCount Exhausted, Re-creating SMTP link******************")
        smtp.Dispose()
        mailcount = 0
        Threading.Thread.Sleep(18000)
        smtp = New SmtpClient("87.101.183.161")
    End If

Pleas, any help on this would be highly appreciated as i have been stuck in this for a week, i have already contacted SMTP provider and they say that everything has been configured correctly at their end and they are not facing any issues with other clients who use the same SMTP server for Emails. 恳请您提供任何帮助,因为我被困了一个星期,我已经联系了SMTP供应商,他们说一切都已正确配置,并且与其他客户之间没有任何问题。对电子邮件使用同一SMTP服务器。

Also, the SMTP object is a static Object before the start of the code and is being re-used. 另外,SMTP对象在代码开始之前是一个静态对象,正在重新使用。

Thanks. 谢谢。

Well i resolved the issue by buying an API. 好吧,我通过购买API解决了这个问题。 If anybody wants to know, its from afterlogic called Mailbee and that usually solved the problem. 如果有人想知道,可以从Afterlogic那里获得,它叫做Mailbee,通常可以解决问题。

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

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