home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "EmailMessage"
- Public Function SendMail(sEmailRecipient As String, sEmailSubject As String, sEmailBody As String)
-
- '-----Send an Email Message using Outlook 98-----
-
- 'Developers Note: In References, the Microsoft Outlook 98 Object Model must be selected for this to work
- ' Actual file is MSOUTL85.OLB
-
- Dim emailOutlookApp As Outlook.Application
- Dim emailNameSpace As Outlook.NameSpace
- Dim emailFolder As Outlook.MAPIFolder
- Dim emailItem As Outlook.MailItem
- Dim EmailRecipient As Recipient
-
- '-----Open Outlook in a background process and the Inbox Folder-----
- Set emailOutlookApp = CreateObject("Outlook.Application.8")
- Set emailNameSpace = emailOutlookApp.GetNamespace("MAPI")
- Set emailFolder = emailNameSpace.GetDefaultFolder(olFolderInbox)
-
- 'Enable the next line to actually see Outlook Open
- 'emailFolder.Display
-
- '-----Create a new mail message, set the recipient, subject, and body-----
- Set emailItem = emailOutlookApp.CreateItem(olMailItem)
- Set EmailRecipient = emailItem.Recipients.Add(sEmailRecipient)
- emailItem.Subject = sEmailSubject
- emailItem.Body = sEmailBody
-
- '-----Send the Email-----
- emailItem.Save
- emailItem.Send
-
- '-----Close the Outlook Application------
- emailOutlookApp.Quit
-
- '----Inform User of Success-----
- MsgBox "Email was sent.", vbInformation
-
- '-----Clear out the memory space held by variables-----
- 'Usually unnecessary but a good practice
-
- Set emailNameSpace = Nothing
- Set emailFolder = Nothing
- Set emailItem = Nothing
- Set emailOutlookApp = Nothing
-
- End Function
-