CodeItBetter Programming Another VB Programming Blog

how to send mail from VB using Microsoft Outlook object.

Posted on July 9, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'MS Office - how to send mail from VB using Microsoft Outlook object.
' 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
Filed under: MS Office Leave a comment
Comments (1) Trackbacks (0)
  1. Hi there
    I tried this thing and when i click the send button it gives me an error
    “With object must be user-defined type,object or variant”

    Since i am a novice i require your help please

    Thanks in anticipation


Leave a comment


 

No trackbacks yet.