Sending RichTextFormat as Body of an Email

  • Thread starter Thread starter kpandian
  • Start date Start date
K

kpandian

Hi Everyone,


I am using System.Web.Mail [C#,Windows Form] to send emails. I am
taking the rtf of a rich text box to populate the string for the body
of the email.


---------------------------------------------------------------------------­----------------------------------------

// Converting the Rtf of richtextboxcontrol to byte array and then to a

stream
Byte[] byt = System.Text.Encoding.Unicode.GetBytes(richTextBox1.Rtf);
Stream output = new MemoryStream(byt);


// reading the stream and getting the values into a string (to be used
as body for my string)
StreamReader reader = new System.IO.StreamReader(output,
System.Text.Encoding.Unicode);
string theString = reader.ReadToEnd();
reader.Close();
---------------------------------------------------------------------------­----------------------------------------



MailMessage objMail = new MailMessage();
objMail.From = "XX";
objMail.To= "YY";
objMail.Cc= "ZZ";
objMail.Priority = System.Web.Mail.MailPriority.High;
objMail.Subject="Email Template";
objMail.BodyFormat = MailFormat.HTML;
objMail.BodyEncoding = System.Text.Encoding.ASCII;


//using the string I got earlier
objMail.Body = theString;


SmtpMail.SmtpServer ="XXXX"; //Give ur mail servers IP address here
SmtpMail.Send(objMail);


---------------------------------------------------------------------------­---------------------------------------



All my clients have Outlook 2003. They get the string as


{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharse­t0

Arial;}{\f1\froman\fprq2\fcharset0 Times New
Roman;}{\f2\fswiss\fprq2\fcharset0 Century
Gothic;}{\f3\fswiss\fcharset0 Arial;}{\f4\fnil\fcharset2 Symbol;}}
{\colortbl
;\red0\green0\blue0;\red255\green0\blue0;\red0\green0\blue255;}
\viewkind4\uc1\pard\cf1


I did a lot of search but could not find the slution yet. Does anyone
had any problems like this before. Any help would be appreciated.


Thanks,
Karthik Pandian
 
AFAIK, System.Web.Mail doesn't support rich-text format. You might want to ask in a C# group, though, since you're not using Outlook objects to create the message.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Hi Everyone,


I am using System.Web.Mail [C#,Windows Form] to send emails. I am
taking the rtf of a rich text box to populate the string for the body
of the email.


---------------------------------------------------------------------------­----------------------------------------

// Converting the Rtf of richtextboxcontrol to byte array and then to a

stream
Byte[] byt = System.Text.Encoding.Unicode.GetBytes(richTextBox1.Rtf);
Stream output = new MemoryStream(byt);


// reading the stream and getting the values into a string (to be used
as body for my string)
StreamReader reader = new System.IO.StreamReader(output,
System.Text.Encoding.Unicode);
string theString = reader.ReadToEnd();
reader.Close();
---------------------------------------------------------------------------­----------------------------------------



MailMessage objMail = new MailMessage();
objMail.From = "XX";
objMail.To= "YY";
objMail.Cc= "ZZ";
objMail.Priority = System.Web.Mail.MailPriority.High;
objMail.Subject="Email Template";
objMail.BodyFormat = MailFormat.HTML;
objMail.BodyEncoding = System.Text.Encoding.ASCII;


//using the string I got earlier
objMail.Body = theString;


SmtpMail.SmtpServer ="XXXX"; //Give ur mail servers IP address here
SmtpMail.Send(objMail);


---------------------------------------------------------------------------­---------------------------------------



All my clients have Outlook 2003. They get the string as


{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharse­t0

Arial;}{\f1\froman\fprq2\fcharset0 Times New
Roman;}{\f2\fswiss\fprq2\fcharset0 Century
Gothic;}{\f3\fswiss\fcharset0 Arial;}{\f4\fnil\fcharset2 Symbol;}}
{\colortbl
;\red0\green0\blue0;\red255\green0\blue0;\red0\green0\blue255;}
\viewkind4\uc1\pard\cf1


I did a lot of search but could not find the slution yet. Does anyone
had any problems like this before. Any help would be appreciated.


Thanks,
Karthik Pandian
 
Hi Sue,

I did manage to send an email with rich text format using Outlook com
objects but there is only one problem now, it says "program is trying
to automatically send e mail on your behalf" and it waits for an Yes
or No! Somehow I need to stop it from doing that and make it automated.
It would be great if you could share anything abt that.

Thanks,
PK
 
See http://www.outlookcode.com/d/sec.htm for your options with regard to the "object model guard" security in Outlook 2000 SP2 and later versions.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Back
Top