VB icon

mSendEmail

Email
Submitted on: 1/1/2015 9:26:00 PM
By: Ian Ippolito (PSC)  
Level: Not Given
User Rating: By 16 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 925
author picture
 
     If you have Outlook 98 you can send email using VB! Use this code for the basis of creating mailing programs!
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :mSendEmail
'**************************************
	
	
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: mSendEmail
' Description:If you have Outlook 98 you can send email using VB! Use this code for the basis of creating mailing programs!
' By: Ian Ippolito (PSC)
'
' Inputs:vcolEmailAddress--collection of string email address
vstrSubject--email subject
vstrBody--email body (use vbCrLf to create lf)
'
' Assumes:Requires outlook 98 installed on your machine.Also, make sure you set a reference in your VB project to the Outlook 98 Type Library or this won't compile.
'**************************************

Sub mSendEmail(ByVal vcolEmailAddress As Collection, _
ByVal vstrSubject As String, _
ByVal vstrBody As String)
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
 
'Return a reference to the MAPI layer
Dim newMail As Outlook.MailItem
'Create a new mail message item
Set ns = ol.GetNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
'set properties
With newMail
'Add the subject of the mail message
.Subject = vstrSubject
'Create some body text
.Body = vstrBody
'**************
'go through all
'addresses passed in
'**************
Dim strEmailAddress As String
Dim intIndex As Integer
For intIndex = 1 To vcolEmailAddress.Count
strEmailAddress = vcolEmailAddress.Item(intIndex)
'Add a recipient and test to make sure that the
'address is valid using the Resolve method
With .Recipients.Add(strEmailAddress)
.Type = olTo
If Not .Resolve Then
'MsgBox "Unable to resolve address.", vbInformation
Debug.Print "Unable to resolve address " & strEmailAddress & "."
'Exit Sub
End If
End With
Next intIndex
''Attach a file as a link with an icon
'With .Attachments.Add _
'("\\Training\training.xls", olByReference)
'.DisplayName = "Training info"
'End With
'Send the mail message
.Send
End With
'Release memory
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub


Other 12 submission(s) by this author

 


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 Not Given 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.