Send Mail with SMTP Server

Submitted by: 
Visitors have accessed this post 4096 times.

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("<a href="mailto:[email protected]com" rel="nofollow">[email protected]</a>", "*****")
  9. SmtpServer.EnableSsl = True
  10. SmtpServer.Port = 587
  11. SmtpServer.Host = "smtp.gmail.com"
  12. mail = New MailMessage()
  13. mail.From = New MailAddress("<a href="mailto:[email protected]-dubai.com" rel="nofollow">[email protected]</a>")
  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

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.