VB icon

Easy Outlook E-Mail w/Attachment

Submitted on: 2/11/2015 3:10:00 AM
By: Dino Roger (from psc cd)  
Level: Beginner
User Rating: By 8 Users
Compatibility: VB 6.0
Views: 2596
     To send an e-mail with outlook with an attachment. Very easy to understand instructions.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: Easy Outlook E-Mail w/Attachment
' Description:To send an e-mail with outlook with an attachment. Very easy to understand instructions.
' By: Dino Roger (from psc cd)

'This is a simple way to use the Outlook reference to send an e-mail with an attachment
'Set the Boolean to true at the end of the SendMail function call to display the e-mail
'instead of automatically sending it.
'* Check the box next to "Microsoft Outlook ## Object Library
'* Copy the below code into a form
Function SendMail(EM_TO, Em_CC, EM_BCC, EM_Subject, EM_Body, EM_Attachment As String, Display As Boolean)
 Dim objOA As Outlook.Application
 Dim objMI As Outlook.MailItem
 Dim obgAtt As Outlook.Attachments
 Set objOA = New Outlook.Application
 Set objMI = objOA.CreateItem(olMailItem)
 If EM_TO <> "" Then objMI.To = EM_TO
 If Em_CC <> "" Then objMI.CC = Em_CC
 If EM_BCC <> "" Then objMI.BCC = EM_BCC
 If EM_Subject <> "" Then objMI.Subject = EM_Subject
 If EM_Body <> "" Then objMI.Body = EM_Body
 If EM_Attachment <> "" Then objMI.Attachments.Add EM_Attachment, 1, , EM_Attachment
 If Display Then
 End If
 Set objOA = Nothing
 Set objMI = Nothing
End Function
Private Sub Form_Load()
 'How to call the SendMail function. If you do not want a function of the main just use two quotes and a comma
 'instead of filling the string variable. Example of a call with a To only:
 'SendMail "SendTo@Address.com", "", "", "", "", "", True
 'The code represented here will error unless a real attachment path is specified.
 SendMail "SendTo@Address.com", "CarbonCopy@Address.com", "BlindCC@Address.com", "SUBJECT", "BODY", "C:\Attachment.txt", False
End Sub

Other 3 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 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.