Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

mailer doesn't send till program ends

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Web Search Store - 18 Mar 2008 20:00 GMT
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)=abc1@def.com

emails(2)=abc2@def.com

emails(3)=abc3@def.com

emails(4)=abc4@def.com

dim emails_count as integer=4

Dim credential As Net.NetworkCredential = New Net.NetworkCredential

credential.UserName = "info@abc.com"

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("info@abc.com", 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("scott@tryols.com", "scott@tyrols.com", "hi", "hi more",
"")

Next

end sub
Anthony Jones - 19 Mar 2008 08:57 GMT
> 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.

Signature

Anthony Jones - MVP ASP/ASP.NET

Web Search Store - 19 Mar 2008 19:59 GMT
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
>> Hello,
>>
[quoted text clipped - 9 lines]
> not
> a synchronous operation.
Patrice - 19 Mar 2008 20:08 GMT
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

> Hello,
>
[quoted text clipped - 30 lines]
>> not
>> a synchronous operation.
Anthony Jones - 20 Mar 2008 10:37 GMT
> Hello,
>
[quoted text clipped - 13 lines]
> 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?

Signature

Anthony Jones - MVP ASP/ASP.NET


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.