Introduction and Sending Email Question

S

SFS

Hello,

I'd like to introduce myself.I have done zero programming since the
days of GWBasic in college. I began using VB.Net 2005 around a month
ago, and even though I've had no formal training, I've found it very
easy to use by looking up docs and examples online, as well as having
found the answers to many of my questions by browsing here. Thanks to
all here! I'm quite sure that my code is not pretty, but it seems to
do the job.

That being said, I have a problem for which I have yet to find a
solution. The follow sub works fine for sending emails from my app,
with the exception that the email is sometimes not sent for two or
three minutes, and in some instances not until another is sent or I
close the app.

Is there a way to "flush" the email cue, or otherwise force the emails
to be sent immediately after this sub is called?

Thanks,

SFS


Sub MailIt(from As String, recipient As String, _
subject As String, body As String, login As String, _
password As String)

Dim mMailMessage As New MailMessage()
Dim client As New SmtpClient("smtp.myhost.com")

client.Credentials = New System.Net.NetworkCredential _
(login, password)
mMailMessage.From = New MailAddress(from)
mMailMessage.To.Add(New MailAddress(recipient))

mMailMessage.Subject = subject
mMailMessage.Body = body
mMailMessage.IsBodyHtml = False
mMailMessage.Priority = MailPriority.Normal

client.Send(mMailMessage)

End Sub
 
G

Guest

Is there a way to "flush" the email cue, or otherwise force the emails
to be sent immediately after this sub is called?

..Send sends the e-mail off to your mail server.

If there are any delays, it might be your local mail server or the remote
mail server... or anything in between ;-)
 
S

ShaneO

SFS said:
Is there a way to "flush" the email cue, or otherwise force the emails
to be sent immediately after this sub is called?
A few days ago I provided the following reply to someone else with
exactly the same question (modified for your code) -

******************
I believe the answer to the Delay problem revolves around the Garbage
Collection of the Mail Message. (I haven't had a problem with this so I
can't be certain).

Try doing the following after your "client.Send(mMailMessage)" line -

mMailMessage.Dispose

If you then find a problem that your Message seems to just vanish (ie.
never gets sent) then do it this way -

System.Threading.Thread.Sleep(100)
mMailMessage.Dispose

Please post back your results so myself (and others) can be aware of
these matters in the future.
******************

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
S

SFS

Try doing the following after your "client.Send(mMailMessage)" line -

mMailMessage.Dispose

If you then find a problem that your Message seems to just vanish (ie.
never gets sent) then do it this way -

System.Threading.Thread.Sleep(100)
mMailMessage.Dispose

Thanks, ShaneO. mMailMessage.Dispose (without the sleep) seems to
have fixed the problem.

SFS
 
S

susiedba

hey dipshit

no matter what you do; do NOT put your marbles in the MS camp

MS does not give a shit about programmers; they have demonstrated this
time and time again


maybe they'll invent L## next month and stop giving a crap about all
this dotnet crap

SERIOUSLY

ms betrayed us all, move to PHP or get shafted eventually
 

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


Top