다음과 같은 문제가 있습니다 :메일 보내기 콘솔 응용 프로그램이 마지막 메일을 보내지 않습니다.
전자 메일을 보내는 콘솔 응용 프로그램을 작성했습니다. 그것은 다음과 같은 방식으로 동작합니다 :
- 이 응용 프로그램을 디버그 모드로 실행하고 코드를 단계별로 실행하면 전자 메일이 전송됩니다.
- 이 응용 프로그램을 디버그 모드로 실행하고 단계별로 코드를 실행하지 않으면 마지막 전자 메일이 보내지지 않습니다.
- 응용 프로그램을 빌드하고 서버로 이동하고 작업을 만들 때 마지막 전자 메일이 보내지지 않습니다.
- 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
을 ???