Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

E-Mail Sends only in debug

Status
Not open for further replies.

plocks

Programmer
Aug 26, 2011
16
US
I have code set up in VB 2008 that updates a few tables, then sends an email with data from a "log" variable. If I run the code in Debug mode, and Step Into each line, it works fine. But if I let the program run by itself with no breakpoints, the email does not send nor do I recieve any errors. Below is my code with "---" to omit sensitive data.

Dim ToAddress As String = "---"
Dim From As String = "---"
Dim Subject As String = "Update Log " & Now().ToString("MM-dd-yyyy")
Dim Body As String = strLog

Dim message As New MailMessage(From, ToAddress)
Dim SettingsSMTPserver As String = "---"
Dim SettingsSMTPport As Integer = 25

Dim mailSender As SmtpClient
mailSender = New SmtpClient(SettingsSMTPserver, SettingsSMTPport)

message.Subject = Subject
message.IsBodyHtml = False
message.Body = Body
Try
mailSender.Send(message)
Catch ex As Exception
Exit Sub
End Try
 

Try throwing in a System.Threading.Thread.Sleep(500) before the send line.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
I've tried that and did not prevail. I've had a program before with a similar problem and added the "sleep" worked, but with this program it's not fixing the issue.
 
Hey, I put in the "Sleep" after the send line and it worked! Fantastic, thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top