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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SMTP Relay/Server in VB2005 4
vb2005 run help 2
mailer question 2
vb2005 to vb2008 express 7
Querying AD using VB2005 1
mail doesn't work on vista business 1
SMTP IN VB.NET HELP 1
VB2005 EXPRESS 2

Back
Top