Results 1 to 2 of 2

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

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2008
    Posts
    6

    Resolved [RESOLVED][Outlook] How to send email

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

    http://support.microsoft.com/?kbid=313803

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

    Code:
    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 = "user@example.com"
    
            ' 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
            oMsg.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
    Posts
    6

    Re: [Outlook] How to send email

    http://forums.msdn.microsoft.com/es-...-2c2aae020265/

    I tried:

    Code:
            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 = "address@company.com"
    
            '***ADD AN ATTACHMENT***
            'This parameter just has to point to a valid file
            msg.Attachments.Add("c:\test.txt")
            '*******************************
            '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
    
            msg.Send()
    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