SMTP Email in VB2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using SMTP for email in a VB2005 application. The problem is that the
email is sent when I exit the application, not at the moment that the
client.Send command is generated.

There's a setting to done to allow the email to be sent at real time?

Thanks a lot.
 
SMTP will send the mail when your application directs it to. There is
no setting, the defaults will work for the most part. Post your
sending code.
 
Here is the code:

Dim sb As New StringBuilder()

sb.Append("The following email was sent to you from WRDCS " & _
"(Warehouse). Please do not reply.")
sb.Append(vbCrLf)
sb.Append(vbCrLf)

sb.Append("Discrepancy in Item: " & Me.txtItem.Text)
sb.Append(vbCrLf)
sb.Append(vbCrLf)
sb.Append("SF: " & vbTab & vbTab & vbTab & Me.txtSF.Text)
sb.Append(vbCrLf)
sb.Append("Reported Weight: " & vbTab & Me.txtNet.Text)
sb.Append(vbCrLf)
sb.Append("Scaled Weight: " & vbTab & vbTab & tmpScaleGrossWeight)
sb.Append(vbCrLf)


Dim mMailMessage As New MailMessage()
Dim client As New SmtpClient(strEmailServer)

mMailMessage.From = New MailAddress("(e-mail address removed)")
mMailMessage.To.Add(New MailAddress(strEmailRecipient))

mMailMessage.Subject = "Discrepancy"
mMailMessage.Body = sb.ToString
mMailMessage.IsBodyHtml = False
mMailMessage.Priority = MailPriority.Normal

client.Send(mMailMessage)

mMailMessage.Dispose()

Thanks a lot
 
I've noticed the same behavior as well when I was experimenting with the
SmtpClient class. Have you found a solution? Waiting until the
application exits before the messages are sent is unacceptable.
Thanks!
 
Osvaldo,

I found this little piece of code for sending an SMTP email message...

http://www.codeproject.com/useritems/VB2005_SMTP_EMail.asp

The only difference I see in the code you provided and the code at the above
link is the Host address, but you can go through the code yourself and see
if there is something that would work for your application. If it still
doesn't send immediately, it could be something in your Exchange server that
is preventing the email from sending immediately.

Bruce W. Darby
 
Try adding credentials

client.Credentials = New Net.NetworkCredential(Me.MailServerUserName,
Me.MailServerPassword)

and you might want to try removing the call to dispose
 
Back
Top