Home > How-To Library > MS Office
how to send mail from VB using Microsoft Outlook object.
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** ' In your project go to References and click Microsoft Outlook 8.0/11.0 Object Library. ' make sure a reference to the Outlook object is set ' place the following code in a command button click event Private Sub cmdSendMail_Click() Dim objOutlook As Outlook.Application Dim objMailItem As Outlook.MailItem Set objOutlook = New Outlook.Application Set objMailItem = objOutlook.CreateItem(olMailItem) With objMailItem.To = "ToAddress" 'recipient's address .Subject = "subject" 'subject box content .Body = "email message" ' message goes here .Attachment = "c:\path\file.txt" ' attach any files here .Send End With Set objMailItem = Nothing Set objOutlook = Nothing End Sub
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.