VB icon

A VB.NET sample showing how to send emails to recipients

Email
Submitted on: 1/1/2015 12:47:00 PM
By: Roby Kott (from psc cd)  
Level: Beginner
User Rating: By 13 Users
Compatibility: VB.NET, ASP.NET
Views: 2022
 
     This Console application, written in Visual Basic .NET, shows how to send (multiple) email messages to (multiple) recipients. Code sample is simple. However, advanced features like embedded attachments, rich text formatting etc. are possible
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A VB.NET sample showing how to send emails to recipients
// Description:This Console application, written in Visual Basic .NET, shows how to send (multiple) email messages to (multiple) recipients. Code sample is simple. However, advanced features like embedded attachments, rich text formatting etc. are possible
// By: Roby Kott (from psc cd)
//**************************************

' Description:Send email(s) to an SMTP server, 
' to multiple recipients, with attachments etc. 
' Easy to use, no IIS or MS SMTP service required.
'
' You need the FREEWARE AEmail.dll to run the sample.
' Download it from http://www.vahland.com/pub/aemail.dll
' and register it on your machine.
' Then, choose 'Add Reference' from your Solutions Window,
' and 'Add' the 'ActivEmail 2.1 Type Library'.
' 
' Read http://www.vahland.com/pub/aemail.htm for more info.
Imports AEMAILLib
Module Module1
Sub Main()
Dim objSmtpMail As AEMAILLib.SmtpMailClass
Console.WriteLine("Be sure To have the FREEWARE AEmail.dll registered on your system,")
Console.WriteLine("and add the ActivEmail 2.1 Type Library to your references.")
Console.WriteLine("Check out the code header about how to obtain the free component.")
Console.WriteLine("")
objSmtpMail = New AEMAILLib.SmtpMailClass()
objSmtpMail.HostName = "yourmailserver.yourdomain.dom"
objSmtpMail.FromName = "Senders Name"
objSmtpMail.FromAddress = "sender@sendersdomain.dom"
objSmtpMail.AddTo("john.doe@domain.dom", "John Doe")
objSmtpMail.Subject = "My Subject"
' If you want, you can include attachment, multiple recipients, rich text formatting etc.
' It's not included in this sample to keep sample straight.
objSmtpMail.Body = "Here is the body text" & vbCrLf & "Best regards..."
objSmtpMail.Send()
Console.WriteLine("Send, result: " & objSmtpMail.LastError.ToString())
objSmtpMail.Clear() ' To use the same object again with all properties cleared
End Sub
End Module


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.