Solved

VB.NET/Outlook Message Display Issue

Posted on 2008-10-13
10
567 Views
Last Modified: 2012-05-05
Hello everyone.

I was working on a very complex macro in VBA using Outlook 2007's macro editor, but then realized the project was more suited for a standalone executable. Feeling working on this in VBA was too outdated, I switched over to VB.NET (on VS Express 2008), and began porting my code.

Everything seems to be working fine as 90% of the code is simple logic, not playing around with Outlook. The one problem I am having is involving code that reads HTML from a file & places it in the HTMLBody of a new Outlook message.

When using VBA code with what appears to be the exact same functionality (see below), I get different results. When I scan the HTML file's text & put it in the messages HTML body using VBA everything ends up fine (images intact, no weird formatting errors).

When I scan the same HTML file using VB.NET code & fill in the HTML body, I get strange formatting errors that are black diamond shaped boxes with question marks inside.  Up until today I was also getting errors stating ""The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, then open the file again. If the red x still appears, you may have to delete the image and then insert it again."  Here's a screenshot of what I'm talking about... http://www.tneus.com/images/screenshot.jpg

Yet when I test the same thing again in VBA (after receiving this error), everything once again still works fine.

The HTML template I am using was exported from an OFT file in Outlook, so there is some strange markup that's not in regular HTML files. I don't know why or how this would affect the display of information though, if everything is working fine with one method.

I've asked this question on several forums (and waited about a week for responses) and have had zero help.  Any help would be GREATLY appreciated, as this is immensely frustrating.

Thank you.
0
Comment
Question by:tnesupport
  • 5
  • 5
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Regarding the diamonds with questions marks, if you notice that the line "Don't Miss Out" has that diamond with question mark in place of ', you would easily understand the source of the problem. In VB.NET, ' is used to comment the code. So anything beyond ' is considered a commend. Try Replacing those characters with chr() function by using appropriate numeric value such as 13 is for vbcrlf.
The formatting may be going wrong because of this basic issue. I think if you solve this problem then other problems would be solved automatically. If not, do come back.
0
 
LVL 1

Author Comment

by:tnesupport
Comment Utility
This may be part of the problem, but your suggestion pointed me in the right direction.  Some diamonds are being caused by whitespace..for example..

<p><span style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
      "Verdana","sans-serif";mso-bidi-font-family:Arial;color:#666666;
      mso-bidi-font-weight:bold'>Call us today to register for this exciting
      preview event. We look forward to seeing you there!<span
      style='mso-spacerun:yes'>  </span><o:p></o:p></span></p>

The whitespace in between <span style='mso-spacerun:yes'>  </span> those two tags is causing this to appear.

This seems like an encoding issue to me but i have 0 experience with this subject...do you have any ideas?
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
I would suggest you to first replace the single quotes as the span has many of these in pairs for styles. If that does not help then look for other problems. The reason is that i send HTML based emails from VB.NET and never had a problem.

Also, never saw this tag before
<o:p></o:p>
0
 
LVL 1

Author Comment

by:tnesupport
Comment Utility
I understand..here's some more info...When I change my streamreader's encoding to ANSI, there is no longer any black diamonds but all the images will not show ("The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, then open the file again. If the red x still appears, you may have to delete the image and then insert it again." )

The tag <o:p></o:p> is something with Microsoft Office..as the HTML file was exported from OFT file.
0
 
LVL 1

Author Comment

by:tnesupport
Comment Utility
Excuse me, when I re-save the file in notepad using UTF8 encoding, and set my stream reader to UTF8 encoding it works...does anyone by any chance know the default encoding when you save a HTML file from outlook?  Does it use the system's default encoding?  Or does anyone know the default encoding of the Scripting.FileSystemObject..?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Did you try other encodings such as UTF?
0
 
LVL 1

Author Comment

by:tnesupport
Comment Utility
This was the solution..the encoding for stream reader needed to be set to Encoding.Default...thanks a lot for helping me see what the problem was here CodeCruiser :).
0
 
LVL 1

Author Closing Comment

by:tnesupport
Comment Utility
Thanks a lot man!
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
The encoding can be changed for outgoing messages through Tools->Options Mail Format tab, and International Options button. I think when saving messages as HTML, the source encoding is used.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Happy that the problem is sorted.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now