Results 1 to 2 of 2

Thread: [RESOLVED][Outlook] How to send email

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008

    Resolved [RESOLVED][Outlook] How to send email

    Hey all, i'm trying to send an output email from my application. I checked out:

    I tried to test this but I get a 'Type 'Outlook.Application is not defined' error.

    Public Sub sendEmail()
            ' Create an Outlook application.
            Dim oApp As Outlook.Application
            oApp = New Outlook.Application()
            ' Create a new MailItem.
            Dim oMsg As Outlook.MailItem
            oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
            oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET"
            oMsg.Body = "Hello World" & vbCr & vbCr
            ' TODO: Replace with a valid e-mail address.
            oMsg.To = ""
            ' Add an attachment
            ' TODO: Replace with a valid attachment path.
            Dim sSource As String = "C:\Temp\Hello.txt"
            ' TODO: Replace with attachment name
            Dim sDisplayName As String = "Hello.txt"
            Dim sBodyLen As String = oMsg.Body.Length
            Dim oAttachs As Outlook.Attachments = oMsg.Attachments
            Dim oAttach As Outlook.Attachment
            oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)
            ' Send
            ' Clean up
            oApp = Nothing
            oMsg = Nothing
            oAttach = Nothing
            oAttachs = Nothing
        End Sub
    I tried adding the reference:

    "Click the COM tab, locate Microsoft Outlook 11.0 Library or Microsoft Outlook 10.0 Object Library, and then click Select. "

    But it does not exist. I added:

    Microsoft Office 11.0 Object Library and
    Microsoft Outlook 11.0 Object Library

    I am currently using Outlook 2003.

    Do I need to add a 'imports' or something?
    Last edited by Hack; Jun 20th, 2008 at 12:07 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2008

    Re: [Outlook] How to send email

    I tried:

            Dim MSO As New Microsoft.Office.Interop.Outlook.Application
            'Create a new Message object
            Dim msg As Microsoft.Office.Interop.Outlook.MailItem
            'Compose the Message
            msg = MSO.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
            msg.Subject = "This is an example message"
            msg.To = ""
            '***ADD AN ATTACHMENT***
            'This parameter just has to point to a valid file
            'If you have SendOnBehalf permissions, you can specify a SOB user
            'msg.SentOnBehalfOfName = "Some Other User"
            ''Create an HTML formatted body
            'Dim body As String
            'body = "<h1>This is an HTML Email</h1><p>Hello, here is a test message.</p>"
            ''Set the body format and contents
            'msg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML
            'msg.HTMLBody = body
            'Send the message
    This works.

    Note the inclusion of "Microsoft.Office. " before Interop.Outlook.Application

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width