By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

MailMessage with a large body

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.