locked
problem in saving mht file from outlook message (Outlook is saving mht file as msg on the disk) RRS feed

  • Question

  • Problem Description:

     I have Outlook message file which is having .mht file attachment, when I am trying to save .mht file from the message on disk it is saving as .msg file

     

    Requirement:

    We need to save file as .mht on disk (In any drive).Because we save all attachment on disk from Outlook message using vb .net then we proceed for further work. We are not able to save .mht file as .mht. Even directly from outlook it is saving .msg file as message .mht file.

    Please provide possible solution for it. Or is there any setting need in Outlook for saving mht file in mht format on disk.

    I will be thankful.


    • Edited by S.P Singh Friday, February 3, 2012 11:08 AM
    Friday, February 3, 2012 11:07 AM

Answers

  • Yes, the MSG, EML and MHTML attchments are converted if the message itself needs to be converted to the MIME format, which happens if you send through SMTP. If you send between two Exchange mailboxes, that never happens, so the attachments arrive intact.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    • Proposed as answer by DamianD Friday, February 3, 2012 2:24 PM
    • Marked as answer by 许阳(无锡) Friday, February 24, 2012 7:42 AM
    Friday, February 3, 2012 2:18 PM

All replies

  • works ok on my machine. Paste code that you use to save attachments.
    Friday, February 3, 2012 11:38 AM
  • Public Sub GetAttachmentsOfCurrentEmail()

    Dim activeExplorer As New Microsoft.Office.Interop.Outlook.Application

    Dim Report As String

    Dim currentExplorer As Explorer

            currentExplorer = activeExplorer.ActiveExplorer

            Try

                Selection = currentExplorer.Selection

                                                    For Each currentItem In Selection

                                                    currentMail = currentItem

                                                                 For Each attachment In currentMail.Attachments

                                                                            Report = Report & GetAttachmentInfo(attachment)

                                                                Next

    Catch ex As System.Exception

    End Try

    End Sub

     

     Public Function GetAttachmentInfo(ByVal attachment As Attachment) As String

            Dim Report As String = ""

            'Report = Report & "Block Level: " & attachment.BlockLevel

            Report = Report & "Display Name: " & attachment.DisplayName

            Report = Report & "File Name: " & attachment.FileName

            Dim fileName As String =  "C:/Addin/Omnidocs_Outlook_Attachment/" &        attachment.FileName

     attachment.SaveAsFile(fileName)

            Report = Report & "Index: " & attachment.Index

            Report = Report & "Path Name: " & attachment.PathName

            Report = Report & "Position: " & attachment.Position

            'Report = Report & "Size: " & attachment.Size

            Report = Report & "Type: " & attachment.Type & vbCrLf

            documentselected.Items.Add(attachment.DisplayName)

            'MsgBox(Report)

            Return Report

        End Function

    • Edited by S.P Singh Friday, February 3, 2012 12:24 PM
    Friday, February 3, 2012 12:20 PM
  • your code (after fixing few syntax errors) works ok - mht file is saved on disk, so problem must be elsewhere. Does your email contain only one attachment(mht file) ? Please debug or print Report variable - what does it say about that attachment?
    Friday, February 3, 2012 12:31 PM
  • I am attaching some screen shot when I am trying to save mht and eml extension It is saving as Message type as .msg

    Please look into this

     


    • Edited by S.P Singh Friday, February 3, 2012 12:52 PM
    Friday, February 3, 2012 12:51 PM
  • Friday, February 3, 2012 12:53 PM
  • It is saving mht and eml as Message files from outlook directly.And the same scenario is working in vb .net code.Why It is saving on your side as mht , It is not clear to me becuase when i am saving

     

    whether from code or outlook It is saving as .msg file.

     

    Is there any setting require in outlook. You can seen the screen shot.In this am trying to save .mht file on disk.

    but when I am saving It .It is saving as message files.

     

    Please help me in this case.

     

    I will thankful.

    Friday, February 3, 2012 1:01 PM
  • Something is wrong because even in UI your mht file get a msg icon, normally it look like this:

    Can you verify by saving new mht file (for example save as in browser) to disk that such icon appears next to the file? Try to create new mail, attach this new mht file from disk and send it to yourself. after recieving that mail, try to save mht attachment to disk, does it work?

    Friday, February 3, 2012 1:12 PM
  • If you send MSG, EML or MHTML file, Outlook converts it into an embedded message, even if the display name is still the original file name.

    Look at the message with OutlookSpy - Attachment.Type is 5 (OlAttachmentType.olEmbeddeditem).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Friday, February 3, 2012 2:01 PM
  • is this dependant on some env or settings? because i send and recieve mht files without any problem.
    Friday, February 3, 2012 2:15 PM
  • Yes, the MSG, EML and MHTML attchments are converted if the message itself needs to be converted to the MIME format, which happens if you send through SMTP. If you send between two Exchange mailboxes, that never happens, so the attachments arrive intact.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    • Proposed as answer by DamianD Friday, February 3, 2012 2:24 PM
    • Marked as answer by 许阳(无锡) Friday, February 24, 2012 7:42 AM
    Friday, February 3, 2012 2:18 PM
  • thank you for explanation.

    Friday, February 3, 2012 2:24 PM
  • Please clear to me how should I resoloved above query issue

    Saturday, February 4, 2012 5:22 AM
  • Yoy can't resolve it - the attachment is an embedded message, not an MHTML file. It's display name happens to include the ".mht" suffix.

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Saturday, February 4, 2012 6:20 AM
  • Thanks for your quick response.

    I need to understand one thing that why outlook is saving .eml and .mht as message file (.msg format).

    Please tell me reson for this so that I can tell to user why they are not able to save .eml and .mht format in exact format.

    I will be thankful.

    Saturday, February 4, 2012 9:03 AM
  • See my explanation above. I am including including it again below:

    The MSG, EML and MHTML attchments are converted if the message itself needs to be converted to the MIME format, which happens if you send through SMTP. If you send between two Exchange mailboxes, that never happens, so the attachments arrive intact.

    If you don't want these files to be converted, you must zip them first.

    This is just the way Outlook works.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Saturday, February 4, 2012 3:25 PM