mailer doesn't send till program ends

W

Web Search Store

Hello,

The code below works to send email through my email system. However,
nothing gets sent till I end the program.

I don't understand why. Maybe someone else does.

Thanks for any help.

Scott
--------------------------

public sub sendemail()

dim emails(5) as string

emails(1)[email protected]

emails(2)[email protected]

emails(3)[email protected]

emails(4)[email protected]

dim emails_count as integer=4

Dim credential As Net.NetworkCredential = New Net.NetworkCredential

credential.UserName = "(e-mail address removed)"

credential.Password = "password"

'Now we 've got everything we need to send the email except an SMTP server.
'To create that just create a new instance of SmtpClient.

Dim client As New Net.Mail.SmtpClient()

'First we need to set up which SMTP server that the SMTP Client needs to use

client.Host = "mail.abc.com"


For i As Integer = 1 To emails_count

Dim msg As New MailMessage("(e-mail address removed)", emails(i))

msg.Subject = "subject" & i.ToString

msg.IsBodyHtml = True

msg.Body = "This is <i>the body</i> of the email message, it can also
contain HTML code in it"

'client.Port = 587

'the first line sets up the address the second we need because gmail uses a
non-standard port.

'Because gmail requires authentication to send a message we need to tell it
about the credentials we set up earlier.

client.UseDefaultCredentials = False

client.Credentials = credential

'client.EnableSsl = True

'The first line tells the SMTP client that we are supplying our own
credentials. The second line sets those credentials to the
NetworkCredentials we set up earlier. The third line tells the SmtpClient
that gmail uses SSL for authentication.

'Everything is ready to go now, all that is needed is to send the message.
Just call the send method supplying the MailMessage we created earlier.

client.Send(msg)

'client.SendAsync("(e-mail address removed)", "(e-mail address removed)", "hi", "hi more",
"")

Next

end sub
 
A

Anthony Jones

Web Search Store said:
Hello,

The code below works to send email through my email system. However,
nothing gets sent till I end the program.

1) what does 'end the program' mean in the context of ASP.NET? Do you mean
until after the loop is complete, when the page request ends, when you
recycle the app pool, or other?

2) How do you know that nothing gets sent until 'program end'? Email is not
a synchronous operation.
 
W

Web Search Store

Hello,

Thanks for answering.

This is a vb.net program. My antivirus is set up to examine outgoing
emails. It only pops up to examine them when I end, completely close, the
vb.net program. Also, I have waited before, and no emails get received
(I'm sending to myself for testing) until I close the program completely.
Then I see the antivirus pop up, and shortly after that I receive the
messages.

Thanks for your help. I have been researching and found nothing to tell the
smtp client to do a 'send/receive' or any such thing. The only thing that
works, is to close the program.

I want to try the asynchronous send, but I did before, and it didn't even
seem to work at all.

Thanks.

Scott
 
P

Patrice

Could it be that you are using a single client instance (i.e. a session) ?

What if you create a new client instance each time ?

--
Patrice

Web Search Store said:
Hello,

Thanks for answering.

This is a vb.net program. My antivirus is set up to examine outgoing
emails. It only pops up to examine them when I end, completely close, the
vb.net program. Also, I have waited before, and no emails get received
(I'm sending to myself for testing) until I close the program completely.
Then I see the antivirus pop up, and shortly after that I receive the
messages.

Thanks for your help. I have been researching and found nothing to tell
the smtp client to do a 'send/receive' or any such thing. The only thing
that works, is to close the program.

I want to try the asynchronous send, but I did before, and it didn't even
seem to work at all.

Thanks.

Scott
 
A

Anthony Jones

Web Search Store said:
Hello,

Thanks for answering.

This is a vb.net program. My antivirus is set up to examine outgoing
emails. It only pops up to examine them when I end, completely close, the
vb.net program. Also, I have waited before, and no emails get received
(I'm sending to myself for testing) until I close the program completely.
Then I see the antivirus pop up, and shortly after that I receive the
messages.

Thanks for your help. I have been researching and found nothing to tell the
smtp client to do a 'send/receive' or any such thing. The only thing that
works, is to close the program.

I want to try the asynchronous send, but I did before, and it didn't even
seem to work at all.


I'm not quite sure why you've cross posted to the aspnet group.

What happens if you disable the antivirus software?
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top