Need help sending email via asp.net in HTML format...

G

Guest

I am sending an email using ASP.NET (C#)
Below is the code. - str is a StringBuilder that contains the HTML text.
The email is being sent but it is getting truncated. Anyone have any idea
why?
System.Web.Mail.MailMessage

MailMessage oMessage = new MailMessage();


oMessage.Priority = MailPriority.Normal;

oMessage.From = "(e-mail address removed)";

oMessage.To = (e-mail address removed);

oMessage.Subject = "Test Mail";

oMessage.Body = str.ToString();

SmtpMail.SmtpServer = "localhost"

oMessage.BodyFormat = MailFormat.Html;

SmtpMail.Send(oMessage);



The email is in HTML format. The email is being sent but it is getting
truncated. It seems like it only allows a certain fixed length through.

Does anyone have any ideas why?
 
F

Fadi El-Eter

I had this problem before in asp but I used ASPEmail so it was easy to solve by using setting the property ContentTransferEncoding = "Quoted-Printable". However, I don't really know if there's a similar option in the System.Web.Mail.MailMessage.

This occurs because your mail server imposes a restriction on the length of individual lines in a message body. According to SMTP specifications, this limit is 76 characters per line.
You have 3 options over here:
1- Insert the end-of-line character pairs chr(13) & chr(10) into your message body as follows: Mail.Body = "line 1" & chr(13) & chr(10) & "line 2" etc.
2- Try to find a way to set the Content-Transfer-Encoding: quoted-printable in your message
3- Use a 3rd party free assembly such as freesmtp http://www.quiksoftcorp.com/freesmtp/

-- Content-Transfer-Encoding: quoted-printable
Fadi El-Eter, itoctopus - http://www.itoctopus.com
 
P

pete

Thanks for the info. I'll look into it
I had this problem before in asp but I used ASPEmail so it was easy to solve by using setting the property ContentTransferEncoding = "Quoted-Printable". However, I don't really know if there's a similar option in the System.Web.Mail.MailMessage.

This occurs because your mail server imposes a restriction on the length of individual lines in a message body. According to SMTP specifications, this limit is 76 characters per line.
You have 3 options over here:
1- Insert the end-of-line character pairs chr(13) & chr(10) into your message body as follows: Mail.Body = "line 1" & chr(13) & chr(10) & "line 2" etc.
2- Try to find a way to set the Content-Transfer-Encoding: quoted-printable in your message
3- Use a 3rd party free assembly such as freesmtp http://www.quiksoftcorp.com/freesmtp/

-- Content-Transfer-Encoding: quoted-printable
Fadi El-Eter, itoctopus - http://www.itoctopus.com
 
P

Peter Papanikolaou

For those who are interested - I figured it out.

The problem was that the HTML body in the email was being sent without any
\carriage returns \line feeds
I beleive the max length of a line for an email is 76 characters. So I
stuck some \r\n every 50 chars or so and it worked.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top