We are currently looking for quality source code contributions for publication in Code of the Week. We are offering to pay from $25 to $200 for each submission we use. The amount primarily depends on the complexity of the source code. An issue like this one would be about $25 to $50. An issue like http://www.codeoftheweek.com/issues/0067.html would get $200 (maybe more).
If you have source code that you would like to submit, use our online submission form at http://www.codeoftheweek.com/submission.html
Be sure to fill out your name and address information so we can mail you your check upon publication.
If you would like to make some extra cash for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html
In this issue we discuss how to send attachments using the Outlook Object Model. We also cover how to use the CC and BCC options when sending messages.
If you have any questions about using this module, let us know at questions@codeoftheweek.com
This week we took what we had from last week and converted it to a class module. This allowed us to add some other features that would have been difficult to implement in a single function call. The cOutlookIntegration module contains several properties and methods that use the Outlook object model. This class assumes the user of this software has Outlook installed on their computer.
In a future issue we might show how to use other useful Outlook messaging features. Send a message to outlook@codeoftheweek.com if you are interested in seeing more about this.
Public Property Let ImportanceFlag(eImportance As OlImportance)
eImportance marks the message with one of the following: olImportanceHigh, olImportanceLow or olImportanceNormal. This option is not supported on all mail systems. The default is depends on how Outlook is configured.
Public Property Let MessageBody(sBody As String)
sBody is the content of the message. sBody can contain new line characters and can be pretty much unlimited in length; although you probably do not want to send a message that is too long.
Public Sub ComposeMessage(Optional olItem As OlItemType = olMailItem)
This is where you should start. For any message you send, you should call ComposeMessage first. The parameter olItem allows you to control what kind of message will be composed. For now all that is supported is olMailItem. Feel free to experiment with the other types at your own leisure.
Public Sub AddRecipient(sRecipient As String, Optional eRecipientType As OlMailRecipientType = olTo)
A recipient is the email address you want to send the message to, such as info@codeoftheweek.com or just "John Doe" (if you are either running a mail system that will resolve the name or have a contact added called John Doe). eRecipientType is the kind of recipient you are adding. The possible choices for this parameter are: olBCC, olCC, or olTo. The default is olTo. olCC will make the recipient appear in the CC address area. olBCC will make the recipient appear in the BCC address area. CC stands for carbon copy. BBC stands for blind carbon copy. Any recipients that appear in the BBC address area will not be shown to the To and CC recipients.
You can call this as many times as necessary to add all your recipients.
Public Property Let Subject(sSubject As String)
The subject of the message.
Public Sub AddAttachment(sFilename As String, sDescription As String)
This method allows you to append an attachment to an email message. This allows you to send files and graphics to another email user. You may call this method as many times as necessary to add all the attachments you want to add. sFilename should specify the FULL path and filename of the file to send. sDescription is a description of the file to be attached.
Public Sub SendMessage()
When all properties and methods are called SendMessage will perform the actual sending of the message you have just created.
The below sample shows how to send a message using the cOutlookIntegration class. It will send a message with an attachment to two email addresses.
Dim ol As New cOutlookIntegration ol.ComposeMessage ol.AddRecipient "outlook@codeoftheweek.com", olTo ol.AddRecipient "outlookorder@codeoftheweek.com", olCC ol.MessageBody = "Test Message" ol.Subject = "Test Subject" ol.AddAttachment "c:\windows\notepad.exe", "Notepad executable" ol.SendMessage
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0113.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html