Call Connect() '/ Connects to my database
Dc = New OleDbCommand("SELECT email.[ID], email.[Host], email.[SMTPPort], _
email.[SSL], email.[Authenticate], email.[UserName], email.[Password], _
email.[Fromemail] FROM email;")
Dc.Connection = DB : Dr = Dc.ExecuteReader
While Dr.Read /' only one row in the dataset
Dim mail As New MailMessage()
Dim smtp As New SmtpClient(Dr("HOST").ToString)
smtp.Port = CInt(Dr("SMTPPort").ToString)
mail.From = New MailAddress(Dr("Fromemail").ToString)
mail.To.Add("[COLOR="Red"]recpt@domain.com[/COLOR]") '<-- change me
mail.Subject = "Hello - test"
mail.Body = "hello"
mail.IsBodyHtml = True
If Dr("Authenticate") Then '/ This is a boolean field in the table true/false
smtp.UseDefaultCredentials = False
smtp.Credentials = New NetworkCredential(Dr("Username").ToString, Dr("Password").ToString)
Else
smtp.UseDefaultCredentials = True
End If
If Dr("SSL") Then '/ This is a boolean field in the table true/false
smtp.EnableSsl = True
Else
smtp.EnableSsl = False
End If
Try
smtp.Send(mail)
Label1.Text = "Email sent"
Catch ex As Exception
MsgBox("Failed to send " & Err.Description)
End Try
End While
End Sub
Dim mail As New MailMessage()
Dim smtp As New SmtpClient("smtp.gmail.com")
smtp.Port = 465
mail.From = New MailAddress("MyMailAddress@gmail.com")
mail.To.Add("Recipient.Name@somewhere.nl") '<-- change me
mail.Subject = "Hello - test"
mail.Body = "hello"
mail.IsBodyHtml = True
smtp.UseDefaultCredentials = False
smtp.Credentials = New NetworkCredential("MyName", "MyPassword")
smtp.EnableSsl = True
Try
smtp.Send(mail)
MsgBox("Email sent")
Catch ex As Exception
MsgBox("Failed to send " & Err.Description)
End Try
Nope.....
"The operation timed out"
I have used the code like this:
VB.NET:Dim mail As New MailMessage() Dim smtp As New SmtpClient("smtp.gmail.com") smtp.Port = 465 mail.From = New MailAddress("MyMailAddress@gmail.com") mail.To.Add("Recipient.Name@somewhere.nl") '<-- change me mail.Subject = "Hello - test" mail.Body = "hello" mail.IsBodyHtml = True smtp.UseDefaultCredentials = False smtp.Credentials = New NetworkCredential("MyName", "MyPassword") smtp.EnableSsl = True Try smtp.Send(mail) MsgBox("Email sent") Catch ex As Exception MsgBox("Failed to send " & Err.Description) End Try
Couldn't be simpeler.
No-go however.
Private Sub sendMail()
Dim obj As New system.net.mail.smtpClient
Dim objSmtpClient As New System.Net.Mail.SmtpClient
Dim mailmsg As New system.net.mail.mailmessage
'SMTP server
objsmtpclient.host = "smtp.server.com"
'Email subject
mailmsg.subject = "Subject"
'SENDING EMAIL
mailmsg = New System.Net.Mail.MailMessage("user@server.com", "to@server.com", mailmsg.Subject, "Message")
objsmtpclient.Send(mailmsg)
End Sub