473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

MailMessage with a large body

Hi There.

I have a small c# problem. I am trying to create a dynamic email body. The
body may be larger than the maximum number of characters a string can have
(256?). I build the string like this:
private void SendEmail()
{
string body = "";

foreach(row in a dataset)
{
body += "First Name: " + dr["FNAME"].ToString();
body += "Last Name: " + dr["LNAME"].ToString();
....a number of different fields to follow.....

body +=" <br><hr>";//add some divider and go to the next record
}

MailMessage msg = new MailMessage();
msg.Body = body; //add the generated text to the email body

SmtpServer smtpServer = new SmtpServer();
smtpServer.Send(msg);
}

Now the email gets sent without any problems, but the body of the email is
cut-off after a certain number of characters.

How can I create an email body that can grow the way I need it to?

Thanks in advance.

Thanks,

John Scott.
Jul 21 '05 #1
4 4280
I believe the max size of a string in .NET is 2147483647 characters,
although you would be mad to use a string of this size when you could use
stringbuilder which is optimized for large string handling.

This type of restriction normally occurs because your mail server imposes a
restriction on the length of individual lines in a message body. The SMTP
specifications suggests 76 characters per line, so ideally you'll need to
add carriage returns into your string at these lenghts.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
"John Scott" <jo*******@despammed.com> wrote in message
news:B7**********************************@microsof t.com...
Hi There.

I have a small c# problem. I am trying to create a dynamic email body. The body may be larger than the maximum number of characters a string can have
(256?). I build the string like this:
private void SendEmail()
{
string body = "";

foreach(row in a dataset)
{
body += "First Name: " + dr["FNAME"].ToString();
body += "Last Name: " + dr["LNAME"].ToString();
....a number of different fields to follow.....

body +=" <br><hr>";//add some divider and go to the next record
}

MailMessage msg = new MailMessage();
msg.Body = body; //add the generated text to the email body

SmtpServer smtpServer = new SmtpServer();
smtpServer.Send(msg);
}

Now the email gets sent without any problems, but the body of the email is
cut-off after a certain number of characters.

How can I create an email body that can grow the way I need it to?

Thanks in advance.

Thanks,

John Scott.

Jul 21 '05 #2
Thanks for the quick reply John.....

So...becuase I'm trying to generate an HTML email should I be trying to
include a new line like this?

body += "<strong>First Name:</strong>" + dr["FIRSTNAME"] + "<BR>\n";
....is that what you mean by adding carriage returns to the string?

On a side note, if I used this:
StringBuilder builder = new StringBuilder();
builder.Append("<strong>First Name:</strong>" + dr["FIRSTNAME"] + "<BR>";

msg.Body = builder.ToString();
SmtpServer.Send(msg);

would that accomplish what I'm trying to do with this large string?

Thanks again for your help.

John.

"John Timney (ASP.NET MVP)" wrote:
I believe the max size of a string in .NET is 2147483647 characters,
although you would be mad to use a string of this size when you could use
stringbuilder which is optimized for large string handling.

This type of restriction normally occurs because your mail server imposes a
restriction on the length of individual lines in a message body. The SMTP
specifications suggests 76 characters per line, so ideally you'll need to
add carriage returns into your string at these lenghts.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
"John Scott" <jo*******@despammed.com> wrote in message
news:B7**********************************@microsof t.com...
Hi There.

I have a small c# problem. I am trying to create a dynamic email body.

The
body may be larger than the maximum number of characters a string can have
(256?). I build the string like this:
private void SendEmail()
{
string body = "";

foreach(row in a dataset)
{
body += "First Name: " + dr["FNAME"].ToString();
body += "Last Name: " + dr["LNAME"].ToString();
....a number of different fields to follow.....

body +=" <br><hr>";//add some divider and go to the next record
}

MailMessage msg = new MailMessage();
msg.Body = body; //add the generated text to the email body

SmtpServer smtpServer = new SmtpServer();
smtpServer.Send(msg);
}

Now the email gets sent without any problems, but the body of the email is
cut-off after a certain number of characters.

How can I create an email body that can grow the way I need it to?

Thanks in advance.

Thanks,

John Scott.


Jul 21 '05 #3
Hi again,

I did end up using the StringBuilder and on each line where I include a
"<br>" tag I also included a \n ---> "<br>\n"

This seemed to fix my problem and I was able to generate a larger email
body...

Thanks again for the help.
John.


"John Timney (ASP.NET MVP)" wrote:
I believe the max size of a string in .NET is 2147483647 characters,
although you would be mad to use a string of this size when you could use
stringbuilder which is optimized for large string handling.

This type of restriction normally occurs because your mail server imposes a
restriction on the length of individual lines in a message body. The SMTP
specifications suggests 76 characters per line, so ideally you'll need to
add carriage returns into your string at these lenghts.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
"John Scott" <jo*******@despammed.com> wrote in message
news:B7**********************************@microsof t.com...
Hi There.

I have a small c# problem. I am trying to create a dynamic email body.

The
body may be larger than the maximum number of characters a string can have
(256?). I build the string like this:
private void SendEmail()
{
string body = "";

foreach(row in a dataset)
{
body += "First Name: " + dr["FNAME"].ToString();
body += "Last Name: " + dr["LNAME"].ToString();
....a number of different fields to follow.....

body +=" <br><hr>";//add some divider and go to the next record
}

MailMessage msg = new MailMessage();
msg.Body = body; //add the generated text to the email body

SmtpServer smtpServer = new SmtpServer();
smtpServer.Send(msg);
}

Now the email gets sent without any problems, but the body of the email is
cut-off after a certain number of characters.

How can I create an email body that can grow the way I need it to?

Thanks in advance.

Thanks,

John Scott.


Jul 21 '05 #4
glad to have helped :0)

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"John Scott" <jo*******@despammed.com> wrote in message
news:EA**********************************@microsof t.com...
Hi again,

I did end up using the StringBuilder and on each line where I include a
"<br>" tag I also included a \n ---> "<br>\n"

This seemed to fix my problem and I was able to generate a larger email
body...

Thanks again for the help.
John.


"John Timney (ASP.NET MVP)" wrote:
I believe the max size of a string in .NET is 2147483647 characters,
although you would be mad to use a string of this size when you could use stringbuilder which is optimized for large string handling.

This type of restriction normally occurs because your mail server imposes a restriction on the length of individual lines in a message body. The SMTP specifications suggests 76 characters per line, so ideally you'll need to add carriage returns into your string at these lenghts.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
"John Scott" <jo*******@despammed.com> wrote in message
news:B7**********************************@microsof t.com...
Hi There.

I have a small c# problem. I am trying to create a dynamic email body.

The
body may be larger than the maximum number of characters a string can have (256?). I build the string like this:
private void SendEmail()
{
string body = "";

foreach(row in a dataset)
{
body += "First Name: " + dr["FNAME"].ToString();
body += "Last Name: " + dr["LNAME"].ToString();
....a number of different fields to follow.....

body +=" <br><hr>";//add some divider and go to the next record
}

MailMessage msg = new MailMessage();
msg.Body = body; //add the generated text to the email body

SmtpServer smtpServer = new SmtpServer();
smtpServer.Send(msg);
}

Now the email gets sent without any problems, but the body of the email is cut-off after a certain number of characters.

How can I create an email body that can grow the way I need it to?

Thanks in advance.

Thanks,

John Scott.


Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Simran | last post by:
I need to set up an automated email system , which means users should not be able to respond back to the emails but at the same time, we need to track bounced emails. This is important as our...
0
by: desi.american | last post by:
I'm using System.Web.Mail to send an email message from an ASP.NET web page. This is the main section of the code. //************* start code ***************************** string mailHost =...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
4
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP...
4
by: John Scott | last post by:
Hi There. I have a small c# problem. I am trying to create a dynamic email body. The body may be larger than the maximum number of characters a string can have (256?). I build the string like...
2
by: asnowfall | last post by:
I am trying to build System.Mail.MailMessage object out of mime encoded SMTP data. I have following questions Byte byteMailData; //mime encoded STMP data for "email with attachment" 1)...
1
by: Stu Lock | last post by:
Hi, I have an app that has beenusing the JMail COM component to generate emails. I would like to switch to the using the .Net 2.0 MailMessage object instead - as it is more portable. The...
0
by: Kevin Hodgson | last post by:
I'm having a problem with System.Web.Mail.MailMessage losing linefeeds when creating an email. This is a VB.NET project. I use a stringbuilder to construct the MailMessage.Body and use vbCrLf...
1
by: Michel Couche | last post by:
Hello, I am starting the development of a newsletter The use of the class MailMessage of System.Net.Mail is quite straightforward for usual contact forms but my question here is "How can I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.