473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4313
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*******@desp ammed.com> wrote in message
news:B7******** *************** ***********@mic rosoft.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>Fi rst 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>Fi rst Name:</strong>" + dr["FIRSTNAME"] + "<BR>";

msg.Body = builder.ToStrin g();
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*******@desp ammed.com> wrote in message
news:B7******** *************** ***********@mic rosoft.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*******@desp ammed.com> wrote in message
news:B7******** *************** ***********@mic rosoft.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*******@desp ammed.com> wrote in message
news:EA******** *************** ***********@mic rosoft.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*******@desp ammed.com> wrote in message
news:B7******** *************** ***********@mic rosoft.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
4561
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 customers are paying for this service, so we need to track the bounced email Id's. This is the code which I have tried:- MailMessage msgRequest = new MailMessage(); msgRequest.BodyFormat = MailFormat.Text; msgRequest.Subject = "Do Not reply to...
0
1347
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 = (System.Configuration.ConfigurationSettings.AppSettings.GetValues("mailserver")); //Get data from page string toAddress =
3
3258
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 = "W-MyPcName.mycompany.com"; mail.To=strTo; mail.Cc=strCC; mail.Bcc=strBCC;
4
7539
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 SP2, and IIS's SMTP and WWW servers are installed. Here is the error trace: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an...
4
391
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 this: private void SendEmail() { string body = ""; foreach(row in a dataset)
2
3093
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) MailMessage.Body = Convert(byteMailData); If I do the above, will MailMessage object extract the Message BODY, Message HEADER and Attachments automatically.
1
4627
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 jmail component allowed me to set both an HTML body and a text body - this meant that if a users' email client didn't support html - the user would see the text only version with an html attachment. The MailMessage object only appears to have one...
0
1173
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 or vbNewLine to format the message body. Double lines always seem to work (vbCrLf & vbCrLf or vbNewLine & vbNewLine) however single linefeeds (vbCrLf or vbNewLine) only work the first few lines in a message, and then they stop working, which...
1
4665
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 reference a CSS file in the header of my newsletter message ?" Here is where I am .... (1) I found a way to reference a web page in the body of the message (ref: http://www.systemwebmail.com/faq/3.2.aspx) Dim mail As New MailMessage()
0
7934
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7870
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6639
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.