473,396 Members | 1,942 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,396 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 4287
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.