2011-08-09 1 views
1

다음과 같은 문제가 있습니다 :메일 보내기 콘솔 응용 프로그램이 마지막 메일을 보내지 않습니다.

전자 메일을 보내는 콘솔 응용 프로그램을 작성했습니다. 그것은 다음과 같은 방식으로 동작합니다 :

  • 이 응용 프로그램을 디버그 모드로 실행하고 코드를 단계별로 실행하면 전자 메일이 전송됩니다.
  • 이 응용 프로그램을 디버그 모드로 실행하고 단계별로 코드를 실행하지 않으면 마지막 전자 메일이 보내지지 않습니다.
  • 응용 프로그램을 빌드하고 서버로 이동하고 작업을 만들 때 마지막 전자 메일이 보내지지 않습니다.
  • Windows 탐색기에서 응용 프로그램을 실행할 때 (.exe 파일을 두 번 클릭) 마지막 전자 메일이 보내지지 않습니다.
  • 명령 프롬프트에서 응용 프로그램을 실행할 때 모든 전자 메일을 보냅니다.

흥미로운 점은 thread.sleep (200)을 넣으면 모든 이메일이 전송된다는 것입니다! ASP 응용 프로그램에서이 코드를 사용하고 있으며 모든 메일이 항상 전송됩니다. 메일에 첨부 파일이있는 경우 메일이 대기열에 있어도 항상 전송됩니다 (그러나 올바르게 작동하는 다른 응용 프로그램입니다). 나는 (클래스 메일 링을 위해) 사용

번호 : 이메일 전송

Public Class Mailer 

     ' Methods 
     Public Sub SendMail() 
      Dim mail As New MailMessage(Me.Sender, Me.To, Me.Subject, Me.Body) 
      mail.IsBodyHtml = True 
      If Not Me.CC.Trim.Equals("") Then 
       mail.CC.Add(Me.CC) 
      End If 
      If Not Me.BCC.Trim.Equals("") Then 
       mail.Bcc.Add(Me.BCC) 
      End If 
      Dim client As New SmtpClient(Me.MailServer) 
      client.Credentials = New NetworkCredential(Me.Username, Me.Password) 
      client.Send(mail) 
      mail.Dispose() 
     End Sub 


     ' Properties 
     Public Property Attachments As String 
      Get 
       Return Me._attachments 
      End Get 
      Set(ByVal value As String) 
       Me._attachments = value 
      End Set 
     End Property 

     Public Property BCC As String 
      Get 
       Return Me._BCC 
      End Get 
      Set(ByVal value As String) 
       Me._BCC = value 
      End Set 
     End Property 

     Public Property Body As String 
      Get 
       Return Me._body 
      End Get 
      Set(ByVal value As String) 
       Me._body = value 
      End Set 
     End Property 

     Public Property CC As String 
      Get 
       Return Me._CC 
      End Get 
      Set(ByVal value As String) 
       Me._CC = value 
      End Set 
     End Property 

     Public ReadOnly Property MailSent As Boolean 
      Get 
       Return Me._mailSent 
      End Get 
     End Property 

     Public Property MailServer As String 
      Get 
       Return Me._mailServer 
      End Get 
      Set(ByVal value As String) 
       Me._mailServer = value 
      End Set 
     End Property 

     Public Property Password As String 
      Get 
       Return Me._password 
      End Get 
      Set(ByVal value As String) 
       Me._password = value 
      End Set 
     End Property 

     Public Property Sender As String 
      Get 
       Return Me._sender 
      End Get 
      Set(ByVal value As String) 
       Me._sender = value 
      End Set 
     End Property 

     Public Property Subject As String 
      Get 
       Return Me._subject 
      End Get 
      Set(ByVal value As String) 
       Me._subject = value 
      End Set 
     End Property 

     Public Property [To] As String 
      Get 
       Return Me._recepients 
      End Get 
      Set(ByVal value As String) 
       Me._recepients = value 
      End Set 
     End Property 

     Public Property Username As String 
      Get 
       Return Me._username 
      End Get 
      Set(ByVal value As String) 
       Me._username = value 
      End Set 
     End Property 


     ' Fields 
     Private _attachments As String 
     Private _BCC As String 
     Private _body As String 
     Private _CC As String 
     Private _mailSent As Boolean 
     Private _mailServer As String 
     Private _password As String 
     Private _recepients As String 
     Private _sender As String 
     Private _subject As String 
     Private _username As String 
    End Class 

코드 : 여기에 무슨 일이 일어나고 무엇

Do While rd.Read 

    Dim m As New LinksMailer.Mailer 

    m.MailServer = ConfigurationSettings.AppSettings.Item("mailServer") 
    m.Username = ConfigurationSettings.AppSettings.Item("mailUsername") 
    m.Password = ConfigurationSettings.AppSettings.Item("mailPassword") 
    m.Sender = ConfigurationSettings.AppSettings.Item("sender") 
    m.To = Conversions.ToString(rd.Item("Email")) 
    m.CC = ConfigurationSettings.AppSettings.Item("Cc") 
    m.BCC = ConfigurationSettings.AppSettings.Item("Bcc") 
    m.Subject = "Some subject...." 
    m.Body = "Some HTML body..." 
    m.SendMail() 

    ' when I add this line everything works!!! 
    ' Threading.Thread.Sleep(200) 
Loop 

을 ???

답변

2

내가 함께 일하는 개발자는 매월 대규모 (100k +) 그룹의 사용자에게 뉴스 레터를 전자 메일로 보내고 보내진 각 메일 사이에 400ms 지연으로 작성됩니다. 그는 메일 서버가 자동으로 그를 스패머로 지목하는 것을 막기 위해이 작업을 수행합니다. SendMail 보안 문제가 발생할 가능성이 있습니다. 한 번에 얼마나 많은 이메일을 발송합니까? 그는 시행 착오에서 400ms에 도착했다.

0

사실 저는 많은 수의 메일 (최대 20 개)을 보내지 않으며 대부분 하나만 보내줍니다. 그러나 응용 프로그램에서 하나의 메일을 보내야 할 때 3 개의 메일을 보내야하는 경우 처음 두 개만 보내고 다른 하나는 보낸다는 것을 알았습니다. 나는 이것이 이것이 문제라고 생각하지 않는다. 이 늦은 응답이 비록

2

는, 나는 사과하지 않을 경우 작동합니다 희망이 코드는 격자 의 마지막 행으로 이메일을 보낼 수있을 것입니다 다음 독자

Dim inte As Integer 
Dim ji As Integer 
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 

     If Grid.Rows.Count > 0 Then 
      Dim inte As Integer = Grid.Rows.Count 
      inte = inte - 1 
      For ji = 0 To inte 
       Dim email As String = Grid.Rows(ji).Cells(4).Text 
       sendmail(email) 
      Next ji 
     End If 

    End Sub 

도움이 될 수 있습니다 희망