Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Either can be used as class module. This will allo...
Author:
Lee Bardoe
E-mail:
Click to e-mail author
Submitted:
3/12/2002
Version:
VB6
Compatibility:
VB6
Category:
ActiveX
Views:
12377
Either can be used as class module. This will allow you to send automatic emails to people adding To,CC,Subject Text, Message Text and attachments via Outlook 97. You need to a reference to the MS Outlook 8.0 Object Library.
Declarations:
'none
Code:
Private NoToRecp As Integer Private NoCCRecp As Integer Private NoAttach As Integer Private x As Integer Private AddressTo(200) As String Private AddressCC(200) As String Private AttachFile(200) As String Public Enum RecipType ToRecip CCRecip End Enum Public Sub SendMail(vbSubject As String, vbMessageText As String) On Error GoTo Message_Sent_Error Dim vbmailobj As Object Set vbmailobj = CreateObject("Outlook.Application") With vbmailobj.CreateItem(olMailItem) For x = 1 To NoToRecp .Recipients.Add AddressTo(x) Next x If NoCCRecp <= 0 Then GoTo end_cc_recp For x = 1 To NoCCRecp .Recipients.Add(AddressCC(x)).Type = olCC Next x end_cc_recp: .Subject = vbSubject .Body = vbMessageText If NoAttach <= 0 Then GoTo end_attach For x = 1 To NoAttach .Attachments.Add AttachFile(x) Next x end_attach: .Send End With GoTo Message_Sent_Ok Message_Sent_Error: MsgBox "There Was An Error Sending This Message. Please Retry!", vbCritical & vbOKOnly, "Message Error!" GoTo End_Message Message_Sent_Ok: MsgBox "Message Has Been Sent Successfully!", vbOKOnly, "Message Confirmation!" End_Message: End Sub Public Sub AddRecipient(vbRecipient As String, Optional RecipientType As RecipType) If vbRecipient = "" Then RecipientType = ToRecip If RecipientType = 0 Then NoToRecp = NoToRecp + 1 If RecipientType = 1 Then NoCCRecp = NoCCRecp + 1 If RecipientType = 0 Then AddressTo(NoToRecp) = vbRecipient If RecipientType = 1 Then AddressCC(NoCCRecp) = vbRecipient Ignore_Add: End Sub Public Sub AddAttachments(vbAttachmentPath As String) If vbAttachmentPath = "" Then GoTo Ignore_Add NoAttach = NoAttach + 1 AttachFile(NoAttach) = vbAttachmentPath Ignore_Add: End Sub Private Sub Class_Initialize() 'Reset Recipient and Attachment Variables NoToRecp = 0 NoCCRecp = 0 NoAttach = 0 'Reset recipient and Attachment Strings AddressTo(0) = "" AddressCC(0) = "" AttachFile(0) = "" End Sub Private Sub Class_Terminate() 'MsgBox "This Fired Ok", vbOKOnly, "Test" End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement