Results 1 to 3 of 3

Thread: Outlook add in: Saving email as MSG gives error "Object reference not set..."

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Outlook add in: Saving email as MSG gives error "Object reference not set..."

    Hi
    I am trying to create a new email in Outlook 2007, and save it to local disc in vb.net.

    It creates the new file, saves it, and I can open it from local disc(by double clicking on file) while outlook is still open.

    But when I close outlook, and then try to open the file from disc, it does show the email message, but WITH an error messagebox saying : "Object reference not set to an instance of an object."

    Anyone have an idea what could be wrong?

    Code:
    Imports Microsoft.Office.Interop.Outlook
    Public Class save_message
    
    Private Sub btn_send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_send.Click
    
    Dim oApp As Outlook.Application
    Dim oMsg As Outlook.MailItem
    oApp = New Outlook.Application()
    oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
    With oMsg
        .To = "[email protected]"
        .Subject = "this is the subject"
        .Body = "this is the body"
    End With
    oMsg.SaveAs("c:\temp.msg", OlSaveAsType.olMSG)
    
    End Sub

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Outlook add in: Saving email as MSG gives error "Object reference not set..."

    If you are creating an Outlook add in then this thread really belongs in the Office Development forum... but anyway - the code you have shown us is for saving the email but you say you get an error when loading the email so show us the code you are using for that.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: Outlook add in: Saving email as MSG gives error "Object reference not set..."

    Hi Chris
    Thanks for you quick response.
    Sorry i did not know there is a outlook section, I created another more detailed thread there:

    http://www.vbforums.com/showthread.p...13#post3853913

    Basically my code saves the message to c:\temp.msg
    But when i try to manually open the file by (double clicking on it in explorer), it gives an error.

    If someone can delete this thread they are welcome.

Tags for this Thread

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