locked
VB .NET code to read .MSG from a disk and write to CSV file. RRS feed

  • Question

  • Hi 

    I could anybody help?

    I a novice to VB. I am trying to automate some task using RPA (Robotic Process Automation) tool. This tool allows to insert snippets of .NET VB code.

    I need  a .Net VB code to do the following.

    I have lots of .MSG file saved on a local disk.
    I want the code to extract the following data from the .MSG file and write it to a CSV file.

    Data required  - To, Sender email ID, Subject, Date/Time received, and the body of the email. 

    The plan is import into Excel.

    Thanks


    Friday, November 1, 2019 9:43 AM

All replies

  • Hi Kodiek,

    Could you share one .MSG file via cloud storage such as OneDrive, Dropbox, etc?
    I will use it as test data.
    Remember to modify/edit personal/vital data in .MSG file, before sharing.

    Regards,

    Ashidacchi -- http://hokusosha.com

    Friday, November 1, 2019 9:57 AM
  • Hi Ashidacchi,

    Appreciate your help with this.

    https://1drv.ms/u/s!Ak_DOTjG9UzDhmAqLgEF7D_HlZQ8?e=PW0pvd

    .MSG is a an Outlook file type. You could also save an email down from Outlook. That if you use Outlook.

    Any way thanks again.

    Regards

    KodieK

    Saturday, November 2, 2019 10:41 PM
  • Hi KodieK,

    Thank you for sharing "Test undel (3.32 KB).msg".
    I don't use Outlook, but have installed/registered Outlook for testing.
    I can open "Test undel (3.32 KB).msg" in Outlook and found it is an HTML format.

    I'm afraid it would be hard to convert an HTML file to a CSV file, because there are many tags in the HTML file and we need to remove these tags.

    BTW, which CVS file do you want?
      a) one mail : one row
      b) one mail : many rows
       

    And I'd like to confirm about programming language.
    Which do you want to use VB.NET or Outlook VBA?

    Regards,


    Ashidacchi -- http://hokusosha.com

    Saturday, November 2, 2019 11:21 PM
  • Hi KodieK,

    Please try to [Export].
    Refer to this article: How to Export Emails From Outlook

    Regards,

    Ashidacchi -- http://hokusosha.com

    Saturday, November 2, 2019 11:32 PM
  • A MSG file is a compound file (structured storage).  It can be read without Outlook by using the the Windows API for structured storage files and the documented format for MSG files.

    However, this is a task that in my opinion is better suited for C++ than VB.NET since the structured storage API uses COM interfaces like IStorage and IStream.

    Saturday, November 2, 2019 11:51 PM
  • I want the code to extract the following data from the .MSG file and write it to a CSV file.

    Data required  - To, Sender email ID, Subject, Date/Time received, and the body of the email. 

    The plan is import into Excel.

    Reading a MSG file is one thing.  Creating a well formatted comma separated value file is another.

    This is not as simple as it might appear from the trivial test MSG file.  Consider a plain text message body that could contain commas, line breaks and quotation marks.

    I suggest you read https://stackoverflow.com/questions/769621/dealing-with-commas-in-a-csv-file

    Sunday, November 3, 2019 9:56 AM
  • To avoid starting from scratch, an internet search may well turn up third-party .net code to read MSG files.

    Sunday, November 3, 2019 3:33 PM