emailing the contents of a richtextbox

  • Thread starter Thread starter plonk
  • Start date Start date
P

plonk

Hi
I'm having a small problem with a vb.net application (Visual Studio
2005)

I'm trying to insert the contents of a Richtextbox.text into the body
of an email.
It all works fine, except when I open the email, all the carriage
returns and linefeeds are stripped out and all the text appears on one
line.

I'd appreciate some suggestions on how I can resolve this.


thanks in advance
Paul.
 
Hi
I'm having a small problem with a vb.net application (Visual Studio
2005)

I'm trying to insert the contents of a Richtextbox.text into the body
of an email.
It all works fine, except when I open the email, all the carriage
returns and linefeeds are stripped out and all the text appears on one
line.

I'd appreciate some suggestions on how I can resolve this.

thanks in advance
Paul.

Assuming you are displaying the email body as html (IsBodyHtml = true)
you would need to replace each crlf with "<br />" to get the
appropriate line breaks. You could probably do that with a simple
Replace(...), or you could loop through the Lines property of the rich
text box. I also think you would have to replace all the different
fonts and colors with <span style="color: MyColor; font-name:
MyFont;"> tags to get that special formatting. I believe I have seen
several rtf to html converters on codeproject.com - so you might look
there if you don't want to roll out an entire solution on your own.

Thanks,

Seth Rowe
 
Assuming you are displaying the email body as html (IsBodyHtml = true)
you would need to replace each crlf with "<br />" to get the
appropriate line breaks. You could probably do that with a simple
Replace(...), or you could loop through the Lines property of the rich
text box. I also think you would have to replace all the different
fonts and colors with <span style="color: MyColor; font-name:
MyFont;"> tags to get that special formatting. I believe I have seen
several rtf to html converters on codeproject.com - so you might look
there if you don't want to roll out an entire solution on your own.

Thanks,

Seth Rowe

Hi,


Simple example for sending email with HTML body.

String strHTMLBody;

strHTMLBody = "<html><head><title>Confirm your News letter.</title></
head><body>Congratulations ! You have successfully completed
registration. Now you need to confirm your registration. Please do
confirm your registration by clicking on the link :From the team at
JobsKen. Regards</body></html> ";

MailMessage oMessage = new MailMessage();
oMessage.Subject = "Confirm your News letter";
oMessage.Body = strHTMLBody;
oMessage.IsBodyHtml = true;
oMessage.From = new MailAddress("(e-mail address removed)");
oMessage.To.Add(new MailAddress(lblContents.Text));
oMessage.Priority = MailPriority.High;

SmtpClient client = new SmtpClient("XXXXX.XXX.com");
client.UseDefaultCredentials = true;
client.Send(oMessage);

Hope this helps.
Database programming using Visual Basic 2005 and Csharp 2005
http://www.vkinfotek.com
 
Hi,


Simple example for sending email with HTML body.

String strHTMLBody;

strHTMLBody = "<html><head><title>Confirm your News letter.</title></
head><body>Congratulations ! You have successfully completed
registration. Now you need to confirm your registration. Please do
confirm your registration by clicking on the link :From the team at
JobsKen. Regards</body></html> ";

MailMessage oMessage = new MailMessage();
oMessage.Subject = "Confirm your News letter";
oMessage.Body = strHTMLBody;
oMessage.IsBodyHtml = true;
oMessage.From = new MailAddress("(e-mail address removed)");
oMessage.To.Add(new MailAddress(lblContents.Text));
oMessage.Priority = MailPriority.High;

SmtpClient client = new SmtpClient("XXXXX.XXX.com");
client.UseDefaultCredentials = true;
client.Send(oMessage);

Hope this helps.
Database programming using Visual Basic 2005 and Csharp 2005
http://www.vkinfotek.com
Thanks I'll try it tonight and see how I get on... :D
 
Back
Top