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
************Sending email through outlook************
Expand|Select|Wrap|Line Numbers
- 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