views:

345

answers:

1

I have an application written in C# that uses Outlook Interop to open a new mail message pre-filled with details the user can edit before manually sending it.

var newMail = (Outlook.MailItem)outlookApplication.CreateItem(
    Outlook.OlItemType.olMailItem);
newMail.To = "[email protected]";
newMail.Subject = "Example";
newMail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
newMail.HTMLBody = "<p>Dear Example,</p><p>Example example.</p>";
newMail.Display(false);

When the same user creates a new message manually the font is set to Calibri or whichever font the user has set as their default. The problem is that the text in the automatic email appears in Times New Roman font which we do not want.

If I view source of one of the delivered emails I can see that Outlook has explicitly set the font in the email source:

// Automated
p.MsoNormal, li.MsoNormal, div.MsoNormal
{
    margin:0cm;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman";
}

// Manual
p.MsoNormal, li.MsoNormal, div.MsoNormal
{
    margin:0cm;
    margin-bottom:.0001pt;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
}

Why are the formats different and how can I get the automated email to use the users default settings? I am using version 11 of the interop assemblies as there is a mix of Outlook 2003 and 2007 installed.

A: 

Since it is an HTML email, you can easily embed whatever styling you want into the actual HTML body. I suspect that is what Outlook is doing when you create a message from the Outlook GUI.

I don't actually know how to get the user settings. I looked through the Outlook API (it is a strange beast), but didn't see anything that would provide access to the default message properties.

Robert Harvey
Not really what I wanted... but probably as good as I'm going to get for now!
Generic Error