The .NET framework provides you with a class called SmtpMail - which under normal circumstances isn't available for use with Windows forms. It's meant for ASP.NET applications and can be found in the library System.Web.Mail namespace. All you've to do to make it work in your WinForm application is include a Reference to the file, System.Web.dll. This can be done by right-clicking on References in your Project explorer and clicking Add reference.
Once you've added this, use the following code to send mails out:
Code:
Imports System;
Imports System.Web.Mail;
Dim EmailTo As String 'Emailaddres for user to send
Dim EmailFrom As String 'Emailaddres for user from
Dim MailSubject As String 'Subject of Mail
Dim MessageBody As String 'Message
Dim ServerName As String 'Server Name - important
ServerName = "<<Your SMTP server's Name>>"
'Similarly, add in EmailTo, EmailFrom etc parameters here
EmailTo = "[email protected]"
EmailFrom = "[email protected]"
...
.....
'Set the SMTP Server's address
SmtpMail.SmtpServer = ServerName
'This is the code that sends out the email based on whatever server information you've set
'Enclosed within Try-Catch block to catch exceptions in case of errors
Try
SmtpMail.Send (EmailFrom, EmailTo, MailSubject, MessageBody)
Catch ex As Exception
MsgBox ( "Delivery Failure: " & ex.Source & ex.Message )
End Try
Hope this helps!
http://www.systemnetmail.com/
Bookmarks