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