mailer doesn't send till program ends

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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@xxxxxxx

emails(2)=abc2@xxxxxxx

emails(3)=abc3@xxxxxxx

emails(4)=abc4@xxxxxxx

dim emails_count as integer=4

Dim credential As Net.NetworkCredential = New Net.NetworkCredential

credential.UserName = "info@xxxxxxx"

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@xxxxxxx", 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)


Next

end sub




.



Relevant Pages

  • vb emailer doesnt send till program ends
    ... The code below works to send email through my email system. ... dim emailsas string ... 'Because gmail requires authentication to send a message we need to tell it ... about the credentials we set up earlier. ...
    (microsoft.public.vb.general.discussion)
  • Re: ASP.NET Impersonation, XmlUrlResolver, and DefaultCredentials
    ... Dim myCache As New CredentialCache ... But I don't want to have to embed credentials in code, ... > Dim resolver As XmlUrlResolver = New XmlUrlResolver ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: ADSI Impersonation Problem
    ... credentials to access Active Directory. ... matches the NetBIOS name of the machine. ... Execute it by Domain User on the Domain joined PC, the script works. ... Dim ComputerName ...
    (microsoft.public.windows.server.active_directory)
  • Re: Sending e-mail - Ron deBruin
    ... In that case the system doesn't know the name of your SMTP server. ... > ' You must be online when you run the sub> Dim iMsg As Object ... > ' Dim Flds As Variant ... > ' Set iConf = CreateObject ...
    (microsoft.public.excel.programming)
  • The remote server returned an error: (401) Unauthorized
    ... Dim errDataSet As DataSet = New DataSet ... Dim myCredCache As CredentialCache = New CredentialCache ...
    (microsoft.public.dotnet.framework.aspnet.webservices)