473,382 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

1
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

************Sending email through outlook************

Expand|Select|Wrap|Line Numbers
  1. oOutBoxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
  2.             oMailItem.SaveSentMessageFolder = oOutBoxFolder            
  3.             oMailItem.To = ToRecipients
  4.             oMailItem.CC = ToCC
  5.             oMailItem.BCC = ToBCC
  6.             oMailItem.Subject = Subj            
  7.             EmbedHTMLGraphic(EmailBody)
  8.             oMailItem = OutlookApp.GetNamespace("MAPI").GetItemFromID(sEntryID)
  9.  
  10.             If SaveAsDraft = True Then
  11.                 Try
  12.  
  13.                     If MakeVisible = True Then
  14.                         oMailItem.Display()
  15.                     End If
  16.                 Catch ex As Exception
  17.                     Throw ex
  18.                 Finally
  19.                     oMailItem = Nothing
  20.                     OutlookApp = Nothing
  21.                 End Try
  22.             Else
  23.                 Try
  24.  
  25.                     oMailItem.Send()
  26.                 Catch ex As Exception
  27.                     Throw ex
  28.                 Finally
  29.                     oMailItem = Nothing
  30.                     OutlookApp = Nothing
  31.                 End Try
  32.             End If
  33.  
  34.  
  35. ************function to set email message body************
  36.  
  37. Sub EmbedHTMLGraphic(ByVal sHTML As String)        
  38.         Dim olAttachs As Outlook.Attachments
  39.         Dim olAttach As Outlook.Attachment        
  40.         Dim mapiSession As MAPI.Session
  41.         Dim mapiMsg As MAPI.Message
  42.         Dim mapiAttachs As MAPI.Attachments
  43.         Dim mapiAttach As MAPI.Attachment
  44.         Dim mapiFields As MAPI.Fields
  45.         Dim mapiField As MAPI.Field
  46.         Const CdoPR_ATTACH_MIME_TAG = &H370E001E
  47.         Dim alCIDKeys As New ArrayList
  48.         Dim htImageList As Hashtable
  49.         Dim AttachmentCount As Integer
  50.  
  51.         Try
  52.             htImageList = GetImageHashTable(sHTML)
  53.             sHTML = sHTMLSource
  54.             olAttachs = oMailItem.Attachments
  55.             AttachmentCount = olAttachs.Count
  56.             For Each sImg As String In htImageList.Keys
  57.                 Dim sFilename As String = htImageList(sImg)
  58.                 If File.Exists(sFilename) = True Then
  59.                     olAttach = olAttachs.Add(sFilename)
  60.                 End If
  61.                 alCIDKeys.Add(sImg)
  62.             Next
  63.             oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
  64.             oMailItem.HTMLBody = sHTML
  65.             oMailItem.Close(Outlook.OlInspectorClose.olSave)
  66.             sEntryID = oMailItem.EntryID
  67.             oMailItem = Nothing
  68.             olAttachs = Nothing
  69.             olAttach = Nothing
  70.             If htImageList.Count = 0 Then Exit Sub
  71.  
  72.             mapiSession.Logon("", "", False, False)
  73.             mapiMsg = mapiSession.GetMessage(sEntryID)
  74.             mapiAttachs = mapiMsg.Attachments
  75.             For iCnt As Integer = AttachmentCount + 1 To mapiAttachs.Count
  76.                 mapiAttach = mapiAttachs.Item(iCnt)
  77.                 mapiFields = mapiAttach.Fields
  78.                 mapiField = mapiFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
  79.                 mapiField = mapiFields.Add(&H3712001E, CStr(alCIDKeys(iCnt - (AttachmentCount + 1))).Substring(4))
  80.  
  81.             Next
  82.  
  83.             mapiMsg.Fields.Add("{0820060000000000C000000000000046}0x8514", 11, True)
  84.             mapiMsg.Update(True, True)
  85.         Catch ex As Exception
  86.         Finally
  87.             Try
  88.                 mapiSession.Logoff()
  89.             Catch
  90.             End Try
  91.             mapiField = Nothing
  92.             mapiFields = Nothing
  93.             mapiMsg = Nothing
  94.             mapiSession = Nothing
  95.         End Try
  96.     End Sub
Feb 10 '10 #1

✓ answered by tlhintoq

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
Expand|Select|Wrap|Line Numbers
  1. Dim olAttachs As Outlook.Attachments
  2.         Dim olAttach As Outlook.Attachment

2 4408
tlhintoq
3,525 Expert 2GB
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.
Feb 10 '10 #2
tlhintoq
3,525 Expert 2GB
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
Expand|Select|Wrap|Line Numbers
  1. Dim olAttachs As Outlook.Attachments
  2.         Dim olAttach As Outlook.Attachment
Feb 10 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: news | last post by:
Before I begin, I realise there's a big war regarding HTML in e-mails. Personally, I don't like it. Unfortunately, I'm being paid by my company to create an automated newsletter for our customers....
2
by: Yan | last post by:
Hi everyone, I got a little problem while sending HTML e-mails with CDONTS. I generate my e-mail body without problems into a string variable. When I display it to the browser via a...
2
by: Siv | last post by:
Hi, I have written an application which is used by sales staff when discussing products with their customers over the phone. It is a database application that holds detailed information about...
5
by: Sean | last post by:
Hi... I want to use the macro/sendobject (or any other procedure) to send the contents of a table (very small, ~5 rows/columns) as an Outlook message body, not as an attachment. Access 2000 will...
7
by: Ray Booysen | last post by:
Hi all I'm sending email via ASP.NET in HTML mode. Each email has exactly one attachment and I do have full access to the SMTP server. However, if I send the email in HTML format, the...
0
by: wulongtea | last post by:
I am trying generate an HTML email message with C# Visual Studio 2003 that has a graphics file embedded in the message. (I know i should be using 2005 and the new classes there, but I cannot upgrade...
21
by: maya | last post by:
hi, I'm designing an HTML email for a client.. I know general guidelines (no CSS, no JavaScript... although I do use limited CSS, inside tags (as in <span style=".."we do this at work and it...
7
by: microsoft access | last post by:
Is there a way to skip the format selection when e-mailing reports? Maybe in the VB coding? I want them to always be sent in an HTML format. Any information is helpful. Thanks.
2
by: Aneesh Pulukkul[MCSD.Net] | last post by:
Hi, I have a HTML page and associated images. I need to send the HTML as email -the email should also display the images at respective places. So am sending the content of HTML file as...
1
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.