Html Image size when added via Microsoft.Office.Interop.Outlook - c#

Using MS outlook 2010, c# in Visual Studio 2012, Microsoft.Office.Interop.Outlook version 14.
I'm trying to use outlook automation to open a new email, pre-populated with some html.
Here's the code:
using Microsoft.Office.Interop.Outlook;
using Outlook = Microsoft.Office.Interop.Outlook;
...
// bring up outlook
Application oApp = new Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = "any#any.com";
string body = System.IO.File.ReadAllText("welcome.html");
oMailItem.HTMLBody = body;
oMailItem.Subject = "Welcome";
oMailItem.Display(false);
Where welcome.html looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body lang="EN-AU">
<p>hello world</p> <!-- XXX : repeat as necessary -->
<p>
<img src="http://www.w3.org/2008/site/images/logo-w3c-mobile-lg" alt="logo" />
</p>
</body>
</html>
Note: any logo (which is not too small) can be used - the one I have used is just an example.
The code works ok, but there is a problem with the logo size.
The problem can occur when the html line marked at XXX is repeated many times, (say 50).
There are two cases:
a) in outlook, before you send the email, scroll down to view the complete document. I noticed that outlook seems to resize the image. When the email is sent, the receiver sees the image in normal size:
b) in outlook, before you send the email, DO NOT scroll down to view the complete document. When the email is received, the image is small. (32 pixels by 32 pixels):
The email resulting from case a) is the desired outcome. But it would be better if the user didn't have to scroll down to preview the whole thing before sending.
Any workarounds ? Using html width and height attributes on img to explicitly set the dimensions seems to work, but this is not desirable because in real life, the image is dynamically selected (so that the size can't be hardcoded). If there was some way (via automation) to simulate previewing the whole email before sending, this might work as well.

Moe,
Outlook uses Word as an email editor. You can read about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following series of articles in MSDN:
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 2 of 2)

Related

C# : Email Tracking By a Beacon Image not working properly in Gmail

I am working on an email engine, I send emails and then read emails view count by embedding a beacon image in my email message body. Whenever email is opened beacon image hits my site URL and I count 1 view from that email opened. But I'm having issue while read view counts in Gmail and Outlook (web clients) etc. like when email comes in the Inbox and user even has not opened his/her email yet(email is still in preview) but my view count goes up to 1...
I want user to open email then I get the view count only...
I'm using C# asp.net.
Preview area comes after body tag. Like:
<body>
<!-- Visually Hidden Preheader Text : BEGIN -->
<div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family: sans-serif;">
PREVIEW TEXT
</div>
<!-- Visually Hidden Preheader Text : END -->
... Email Body ....
I think you should place your beacon image to bottom of the html after apply above rule.
Also check this link out: https://litmus.com/blog/the-ultimate-guide-to-preview-text-support

C# Outlook doesn't load css in alternate view

As in the topic. I use Outlook as email program, SmtpClient, and MailMessage to send email. I also add AlternateViews, like "text/calendar" (.ics file), and "text/html", which is a html document (I mean it has all tags: <html>,<head>,<body>). The second alternate view (html), does not load css (css I situate in <head><style> my css </style>). The content of <body> is swap dynamically. The MailMessage.Body is null. When I one alternate view (only html, without ics file), css are load. I tried to add css as another alternate view and as attachment. It doesn't work. How to do that?
It works on Outlook Web App, but how to do that in Outlook?
Outlook uses Word for rendering HTML markup. You can read about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following articles:
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 2 of 2)
Appointment items in Outlook use the RTF markup for bodies, not HTML. See the RTFBody property which returns a Byte array that represents the body of the Microsoft Outlook item in Rich Text Format.
Sub GetRTFBodyForMeeting()
Dim oAppt As Outlook.AppointmentItem
Dim strRTF As String
If Application.ActiveInspector.CurrentItem.Class = olAppointment Then
Set oAppt = Application.ActiveInspector.CurrentItem
strRTF = StrConv(oAppt.RTFBody, vbUnicode)
Debug.Print strRTF
End If
End Sub

Using MathML and JavaScript inside WebBrowser component

I have the following webpage in HTML using MathML. In my Firefox, this displays a nice mathematical equation $a x^2 + b x + c$, as MathML should.
I figured I could now load this webpage into the WebBrowser of my Visual Studio 2015 WPF Application. However, the MathML does not render as expected. I suppose the WebBrowser component is not capable of dealing with MathML.
I have a second webpage using JavaScript, which I need for similar reasons. This, too, works in Firefox but not inside the WebBrowser of Visual Studio.
Any suggestions?
<html>
<head>
<title>
Title
</title>
</head>
<body>
MathML:
<br>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mi>a</mi>
<mo>&InvisibleTimes;</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mi>b</mi>
<mo>&InvisibleTimes; </mo>
<mi>x</mi>
<mo>+</mo>
<mi>c</mi>
</mrow>
</math>
</body>
</html>
MathML is not yet supported by the WebBrowser in Visual Studio (probably IE). Math can be typeset using CSS and javascript. A webpage would then need to include
<!-- saved from url=(0014)about:internet -->
in order not to get the pop-up "Allow blocked content".

Click on dynamically generated element after body onload using Selenium

I'll do my best to convey my situation as the date I can give you is limited.
There is this button inside a webpage when clicked creates a new tab whose HTML source is somewhat like below.
<HTML><HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">
<TITLE>Report Viewer Webpage</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<SCRIPT src="javascript1.js"></SCRIPT>
<SCRIPT src="javascript2.js"></SCRIPT>
<SCRIPT src="anotherJavascript.js"></SCRIPT>
</HEAD>
<BODY onload="CallInit('ABC_DEFG_HIJKL_1_',''); window_onload();" onhelp=common_ShowHelp() leftMargin=0 topMargin=0 bgColor=#c6c6c6 currJsHelpVar="help_reports_viewer_dlg">
<OBJECT id=CRViewer codeBase="/viewer/activeXViewer/activexviewer.cab#Version=9,2,0,442" classid=CLSID:1123452WDUIHED:1325726GDUJBEA:12R432VD width="100%" height="99%" VIEWASTEXT>
<PARAM NAME="lastProp" VALUE="500">
<!--Bunch of other params go here-->
<PARAM NAME="_cx" VALUE="26987">
<SCRIPT language=VBScript>
<!--Some Business Logic-->
</SCRIPT>
<OBJECT id=ReportSource codeBase="/viewer/activeXViewer/activexviewer.cab#Version=9,2,0,442" classid=CLSID:1123452WDUIHED:1325726GDUJBEA:12R432VD width="1%" height="1%"></OBJECT>
<OBJECT id=ViewHelp codeBase="/viewer/activeXViewer/activexviewer.cab#Version=9,2,0,442" classid=CLSID:1123452WDUIHED:1325726GDUJBEA:12R432VD width="1%" height="1%"></OBJECT>
</BODY>
</HTML>
And the page content look something like this:
And of course this is a Crystal Report.
All I want to do is click on the neat little Export button sitting right beside Print button above the text preview.
And I am using Selenium to automate all this. But the problem is, selenium only works with HTML elements and I believe the buttons in the page are ActiveX controls or something else. And they are only loaded after the call to <Body> tag's onLoad call.
One of the biggest constraint is that this application only works in IE and the power of IE developer tools is not enabling me to inspect the button element. IE developer tools just doesn't see those buttons as HTML elements. They don't exist to IE developer tools. I am using IE 9 by the way.
What would help me in automating the clicking of that Export button ? Any javascript would help ??
When I inspected this webpage, the first <Object> right after the <Body> is taking all the space of the view. And I think that randomly generated elements are going inside it dynamically.
You can try FluentAutomation. It is written on top of Selenium and has Click on (x, y) coordinate function. I've managed to get it working for Crystal report. Please let me know if you have any problem.
Cheers,
Given the HTML code you're showing, it seems that the content of the page is an ActiveX.
As a result, there is no way for you to do any kind of automation with Selenium as you said it yourself, Selenium only works with HTML.

How to set width of the text in System.Windows.Forms.WebBrowser?

I am currently using the control System.Windows.Forms.WebBrowser to create an Wysiwyg editor in a windows application.
Basically what I need is that the text does not exceed the width of the control, ie I do not want to use a horizonal scrollbar.
Is it possible?
[UPDATE]
this is the code for the moment I am running:
Reconocimiento.Navigate("about:blank"); //this is my object System.Windows.Forms.WebBrowser
Reconocimiento.Document.OpenNew(false);
string html = "<html><head><style type=\"text/css\">body {width: 400px;}</style></head><body></body></html>";
Reconocimiento.Document.Write(html);
recon = (Reconocimiento.Document.DomDocument) as IHTMLDocument2;
recon.designMode = "On"; //What we just did was make our web browser editable!
You can make use of the css word-break property.
Create a file with the following contents and save it to say C:\default.html (or some application path)
<html>
<body style='word-break: break-all'>
<body>
</html>
In you code, instead of navigating to about:blank, call
Reconocimiento.Navigate(new Uri("file:///C:/default.html"));

Categories