Sending outlook mail in HTML format fails

  • Thread starter Thread starter ViperGTS-R
  • Start date Start date
V

ViperGTS-R

Hello,

I've developed a program that can send mails using outlook.
As long as I use plain text there is no problem.
If I set the format to HTML the send message is empty.
If I display the mailitem before sending it has the HTML text, if I click on
the send button then the body is empty.

Can anyone help me solve this.

Greetings
ViperGTS-R
 
Outlook version is outlook 2002 SP2

Sample is a part of th ecomplete application. The outlookobject holds the
reference to the OutlookApplication class. Code written in C# .NET

using System;

using Outlook;

using System.Text;

namespace Mail

{

/// <summary>

/// Summary description for MailMessage.

/// </summary>

public class MailMessage

{

private Outlook.Application olApplication;

private Outlook.NameSpace olNS;

private Outlook._MailItem olMailItem;

private Outlook.MAPIFolder oOutboxFolder;


private int format;

public int Format

{

get

{

return format;

}

set

{

format = value;

}

}

private TextLines lines;

public TextLines Lines

{

get

{

return lines;

}

}

private string replyaddress;

public string ReplyAddress

{

get

{

return replyaddress;

}

set

{

replyaddress = value;

}

}

private string toaddress;

public string To

{

set

{

toaddress = value;

}

get

{

return(toaddress);

}

}


private string subject;

public string Subject

{

get

{

return subject;

}

set

{

subject = value;

}

}

public MailMessage(OutlookObject outlookObject)

{

olApplication = outlookObject.OutlookApplication;

olNS = outlookObject.OutlookNameSpace;

lines = new TextLines();

olMailItem =
(Outlook._MailItem)olApplication.CreateItem(Outlook.OlItemType.olMailItem);

}

public void Send()

{

if(toaddress.Length != 0)

{

olMailItem.To = toaddress;

//olNS.Logon(null,null,true,true);

//gets defaultfolder for my Outlook Outbox

oOutboxFolder =
olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);


olMailItem.Subject = subject;

if(replyaddress.Length != 0)

olMailItem.ReplyRecipients.Add(replyaddress);

olMailItem.SaveSentMessageFolder =
olNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);

//adds it to the outbox

switch(format)

{

case 1:

olMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;

if(lines.Count > 0)

olMailItem.Body = extractLines();

break;

case 2:

olMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

if(lines.Count > 0)

olMailItem.HTMLBody = extractLines();

break;

}

olMailItem.Display(false);

olMailItem.Save();

olMailItem.Send();

}

}

private string extractLines()

{

StringBuilder sb;

sb = new StringBuilder();

foreach(string ln in lines)

{

sb.Append(ln);

if(format == 1)

sb.Append("\r\n");

}

return sb.ToString();

}

}

}
 
What happens if you create the HTML format message just by setting HTMLBody,
without setting BodyFormat?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top