Send Mail with SMTP Server

Sample code on how to send mail using SMTP Server.
  1. Public Function mailcall(ByVal mail_id)
  2.  
  3. Try
  4.  
  5.         SmtpServer.Credentials = New  _
  6.  
  7.  
  8.         Net.NetworkCredential("[email protected]", "*****")
  9.         SmtpServer.EnableSsl = True
  10.         SmtpServer.Port = 587
  11.         SmtpServer.Host = "smtp.gmail.com"
  12.         mail = New MailMessage()
  13.         mail.From = New MailAddress("[email protected]")
  14.         mail.To.Bcc.add(mail_id)
  15.         mail.Subject = "Test Mail"
  16.         mail.IsBodyHtml = True
  17.         mail.Body = "This is for testing SMTP mail"
  18.         'Dim attachment As System.Net.Mail.Attachment
  19.         'attachment = New System.Net.Mail.Attachment("C:\Users\Taher\Pictures\24072011.jpg")
  20.         'mail.Attachments.Add(attachment)
  21.         SmtpServer.Send(mail)
  22.         MsgBox("mail send")
  23.     Catch ex As Exception
  24.         MsgBox(ex.ToString)
  25.     End Try
  26.     Me.close()
  27. End Function
  28. 'and call with
  29.  
  30.     For i = 0 To ds.Tables(0).Rows.Count - 1
  31.         send_mail.mailcall(ds.Tables(0).Rows(i).Item(0).ToString)
  32.     Next

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment