pictures in embedded HTML body shown as attachment in sending mails through outlook

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pkn6
    New Member
    • Jun 2007
    • 1

    pictures in embedded HTML body shown as attachment in sending mails through outlook

    Hi All,
    I am using VB.net to send my mails through outlook. Where i am giving the resource path for the pictures inserted in to it.
    But Email shows the inline pictures as attachments. what could be the reason?
    The important thing is that this is not happening all the time. if we send 5 to 10 times we get the expected result for 2 or 3 times.
    i explored some of the forums , got answers like 'changing the settings, security settings of the office outlook. that too is not succeeded.
    I am giving you the code I am using in my project.
    Could you please tell me if i have done anything wrong with the same or please mention if i missed any code.

    awaiting for your valuable reply,

    thanks in advance,

    The code is given below

    ************Sen ding email through outlook******** ****

    Code:
    oOutBoxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
                oMailItem.SaveSentMessageFolder = oOutBoxFolder            
                oMailItem.To = ToRecipients
                oMailItem.CC = ToCC
                oMailItem.BCC = ToBCC
                oMailItem.Subject = Subj            
                EmbedHTMLGraphic(EmailBody)
                oMailItem = OutlookApp.GetNamespace("MAPI").GetItemFromID(sEntryID)
                
                If SaveAsDraft = True Then
                    Try
                        
                        If MakeVisible = True Then
                            oMailItem.Display()
                        End If
                    Catch ex As Exception
                        Throw ex
                    Finally
                        oMailItem = Nothing
                        OutlookApp = Nothing
                    End Try
                Else
                    Try
                        
                        oMailItem.Send()
                    Catch ex As Exception
                        Throw ex
                    Finally
                        oMailItem = Nothing
                        OutlookApp = Nothing
                    End Try
                End If
    
    
    ************function to set email message body************
    
    Sub EmbedHTMLGraphic(ByVal sHTML As String)        
            Dim olAttachs As Outlook.Attachments
            Dim olAttach As Outlook.Attachment        
            Dim mapiSession As MAPI.Session
            Dim mapiMsg As MAPI.Message
            Dim mapiAttachs As MAPI.Attachments
            Dim mapiAttach As MAPI.Attachment
            Dim mapiFields As MAPI.Fields
            Dim mapiField As MAPI.Field
            Const CdoPR_ATTACH_MIME_TAG = &H370E001E
            Dim alCIDKeys As New ArrayList
            Dim htImageList As Hashtable
            Dim AttachmentCount As Integer
    
            Try
                htImageList = GetImageHashTable(sHTML)
                sHTML = sHTMLSource
                olAttachs = oMailItem.Attachments
                AttachmentCount = olAttachs.Count
                For Each sImg As String In htImageList.Keys
                    Dim sFilename As String = htImageList(sImg)
                    If File.Exists(sFilename) = True Then
                        olAttach = olAttachs.Add(sFilename)
                    End If
                    alCIDKeys.Add(sImg)
                Next
                oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
                oMailItem.HTMLBody = sHTML
                oMailItem.Close(Outlook.OlInspectorClose.olSave)
                sEntryID = oMailItem.EntryID
                oMailItem = Nothing
                olAttachs = Nothing
                olAttach = Nothing
                If htImageList.Count = 0 Then Exit Sub
    
                mapiSession.Logon("", "", False, False)
                mapiMsg = mapiSession.GetMessage(sEntryID)
                mapiAttachs = mapiMsg.Attachments
                For iCnt As Integer = AttachmentCount + 1 To mapiAttachs.Count
                    mapiAttach = mapiAttachs.Item(iCnt)
                    mapiFields = mapiAttach.Fields
                    mapiField = mapiFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
                    mapiField = mapiFields.Add(&H3712001E, CStr(alCIDKeys(iCnt - (AttachmentCount + 1))).Substring(4))
                    
                Next
    
                mapiMsg.Fields.Add("{0820060000000000C000000000000046}0x8514", 11, True)
                mapiMsg.Update(True, True)
            Catch ex As Exception
            Finally
                Try
                    mapiSession.Logoff()
                Catch
                End Try
                mapiField = Nothing
                mapiFields = Nothing
                mapiMsg = Nothing
                mapiSession = Nothing
            End Try
        End Sub
    Last edited by tlhintoq; Feb 10 '10, 12:21 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      But Email shows the inline pictures as attachments. what could be the reason?
      Is it just me... or is this a trick question?

      I don't do VB... I don't do programmatic control of Outlook... but this looked rather obvious
      Code:
      Dim olAttachs As [B]Outlook.Attachments[/B]
              Dim olAttach As [B]Outlook.Attachment[/B]

      Comment

      Working...