473,396 Members | 2,017 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.

Mail Subject gets chopped

I've got some code that is chopping my subject line on the messages I
receive, and I do not know why.

Our server is running Active Directory and SQL Server 2000 Enterprise.

The email is sent, but all we see in the subject line is "S".

Here is what I am doing:
Expand|Select|Wrap|Line Numbers
  1. private bool SendMessage(string fcn)
  2. {
  3. MailMessage email = new MailMessage(fcn, fcn);
  4. email.SubjectEncoding = Encoding.Unicode;
  5. email.BodyEncoding = Encoding.Unicode;
  6. email.Subject = string.Format("SystemID {0} - {1}", m_systemId,
  7. m_coil.SerialNumber);
  8. string fmt = "<html><body bgcolor={0}><div><h3>Coil {1}<br/><font
  9. color=\"red\">{2}</fontApproved Override For {3}</h3><hr><table border=1>";
  10. string body1 = string.Format(fmt, split.Panel1.BackColor.Name,
  11. m_coil.SerialNumber, m_dbase.Supervisor.FullName, m_dbase.Employee.FullName);
  12. string body2 = string.Empty;
  13. foreach (ListViewItem i in ListView1.Items)
  14. {
  15. if (i.ImageKey == "stop.ico")
  16. {
  17. body2 += string.Format("<tr><td>{0} Issue:</td><td><b><font
  18. color=\"green\">{1}</font></b></td></tr>", i.SubItems[0].Text,
  19. i.SubItems[1].Text);
  20. }
  21. }
  22. if (0 < body2.Length)
  23. {
  24. string body3 = "</table><hr></div><div>End Of File</div></body></html>";
  25. email.IsBodyHtml = true;
  26. email.Body = body1 + body2 + body3;
  27. SmtpClient Client = new SmtpClient("172.16.8.200");
  28. try
  29. {
  30. Client.Send(email);
  31. }
  32. catch (Exception err)
  33. {
  34. Console.WriteLine(err.Message);
  35. }
  36. finally
  37. {
  38. email.Dispose();
  39. }
  40. }
  41.  
Jun 27 '08 #1
3 1727
On Jun 16, 8:24*am, jp2msft <jp2m...@discussions.microsoft.comwrote:
I've got some code that is chopping my subject line on the messages I
receive, and I do not know why.

Our server is running Active Directory and SQL Server 2000 Enterprise.

The email is sent, but all we see in the subject line is "S".

Here is what I am doing:
Expand|Select|Wrap|Line Numbers
  1. private bool SendMessage(string fcn)
  2. {
  3. * MailMessage email = new MailMessage(fcn, fcn);
  4. * email.SubjectEncoding = Encoding.Unicode;
  5. * email.BodyEncoding = Encoding.Unicode;
  6. * email.Subject = string.Format("SystemID {0} - {1}", m_systemId,
  7. m_coil.SerialNumber);
  8. * string fmt = "<html><body bgcolor={0}><div><h3>Coil {1}<br/><font
  9. color=\"red\">{2}</fontApproved Override For {3}</h3><hr><table border=1>";
  10. * string body1 = string.Format(fmt, split.Panel1.BackColor.Name,
  11. m_coil.SerialNumber, m_dbase.Supervisor.FullName, m_dbase.Employee.FullName);
  12. * string body2 = string.Empty;
  13. * foreach (ListViewItem i in ListView1.Items)
  14. * {
  15. * * if (i.ImageKey == "stop.ico")
  16. * * {
  17. * * * body2 += string.Format("<tr><td>{0} Issue:</td><td><b><font
  18. color=\"green\">{1}</font></b></td></tr>", i.SubItems[0].Text,
  19. i.SubItems[1].Text);
  20. * * }
  21. * }
  22. * if (0 < body2.Length)
  23. * {
  24. * * string body3 = "</table><hr></div><div>End Of File</div></body></html>";
  25. * * email.IsBodyHtml = true;
  26. * * email.Body = body1 + body2 + body3;
  27. * * SmtpClient Client = new SmtpClient("172.16.8.200");
  28. * * try
  29. * * {
  30. * * * Client.Send(email);
  31. * * }
  32. * * catch (Exception err)
  33. * * {
  34. * * * Console.WriteLine(err.Message);
  35. * * }
  36. * * finally
  37. * * {
  38. * * * email.Dispose();
  39. * * }}
  40.  
I don't see anything obviously wrong with your formatting of the
subject. What is the type
of MailMessage.Subject?

Matt
Jun 27 '08 #2
Basic stuff. I made some mods so it would fill a string var first, and the
input was this: "SystemID AA_Water_08 - C189335 1107 94"

After spending time with it, I found a MS example on MSDN where they created
just about the entire email in the initialization:

email = new MailMessage(fromName, toName, subjectValue, bodyValue);

The bodyValue is Text only, so I wrote there that the document was formatted
for HTML, then filled the body with HTML and set the IsHtml flag.

Now it works. I don't really get what the problem was, but I'm up and running.

"Matt" wrote:
On Jun 16, 8:24 am, jp2msft <jp2m...@discussions.microsoft.comwrote:
I've got some code that is chopping my subject line on the messages I
receive, and I do not know why.

Our server is running Active Directory and SQL Server 2000 Enterprise.

The email is sent, but all we see in the subject line is "S".

Here is what I am doing:
Expand|Select|Wrap|Line Numbers
  1.  private bool SendMessage(string fcn)
  2.  {
  3.    MailMessage email = new MailMessage(fcn, fcn);
  4.    email.SubjectEncoding = Encoding.Unicode;
  5.    email.BodyEncoding = Encoding.Unicode;
  6.    email.Subject = string.Format("SystemID {0} - {1}", m_systemId,
  7.  m_coil.SerialNumber);
  8.    string fmt = "<html><body bgcolor={0}><div><h3>Coil {1}<br/><font
  9.  color=\"red\">{2}</fontApproved Override For {3}</h3><hr><table border=1>";
  10.    string body1 = string.Format(fmt, split.Panel1.BackColor.Name,
  11.  m_coil.SerialNumber, m_dbase.Supervisor.FullName, m_dbase.Employee.FullName);
  12.    string body2 = string.Empty;
  13.    foreach (ListViewItem i in ListView1.Items)
  14.    {
  15.      if (i.ImageKey == "stop.ico")
  16.      {
  17.        body2 += string.Format("<tr><td>{0} Issue:</td><td><b><font
  18.  color=\"green\">{1}</font></b></td></tr>", i.SubItems[0].Text,
  19.  i.SubItems[1].Text);
  20.      }
  21.    }
  22.    if (0 < body2.Length)
  23.    {
  24.      string body3 = "</table><hr></div><div>End Of File</div></body></html>";
  25.      email.IsBodyHtml = true;
  26.      email.Body = body1 + body2 + body3;
  27.      SmtpClient Client = new SmtpClient("172.16.8.200");
  28.      try
  29.      {
  30.        Client.Send(email);
  31.      }
  32.      catch (Exception err)
  33.      {
  34.        Console.WriteLine(err.Message);
  35.      }
  36.      finally
  37.      {
  38.        email.Dispose();
  39.      }}
  40.  
  41.  

I don't see anything obviously wrong with your formatting of the
subject. What is the type
of MailMessage.Subject?

Matt
Jun 27 '08 #3
jp2msft wrote:
I've got some code that is chopping my subject line on the messages I
receive, and I do not know why.

Our server is running Active Directory and SQL Server 2000 Enterprise.

The email is sent, but all we see in the subject line is "S".
Sounds like a unicode encoding issue. If you want to use non-ASCII
characters in e-mail, you have to specify the encoding in the MIME headers.
If you want to use Unicode, you have to use UTF-8 encoding. Windows'
default encoding of UTF-16 results in NUL bytes in the stream which would
explain the truncation.

At least this is all true if you use SMTP. If your e-mails are local to an
Exchange Server (you did mean Exchange, not SQL, right?) then different
rules might apply.
>
Here is what I am doing:
Expand|Select|Wrap|Line Numbers
  1. private bool SendMessage(string fcn)
  2. {
  3.  MailMessage email = new MailMessage(fcn, fcn);
  4.  email.SubjectEncoding = Encoding.Unicode;
  5.  email.BodyEncoding = Encoding.Unicode;
  6.  email.Subject = string.Format("SystemID {0} - {1}", m_systemId,
  7. m_coil.SerialNumber);
  8.  string fmt = "<html><body bgcolor={0}><div><h3>Coil {1}<br/><font
  9. color=\"red\">{2}</fontApproved Override For {3}</h3><hr><table
  10.  border=1>"; string body1 = string.Format(fmt,
  11. split.Panel1.BackColor.Name, m_coil.SerialNumber,
  12.  m_dbase.Supervisor.FullName, m_dbase.Employee.FullName); string
  13.  body2 = string.Empty; foreach (ListViewItem i in ListView1.Items)
  14.  {
  15.    if (i.ImageKey == "stop.ico")
  16.    {
  17.      body2 += string.Format("<tr><td>{0} Issue:</td><td><b><font
  18. color=\"green\">{1}</font></b></td></tr>", i.SubItems[0].Text,
  19. i.SubItems[1].Text);
  20.    }
  21.  }
  22.  if (0 < body2.Length)
  23.  {
  24.    string body3 = "</table><hr></div><div>End Of
  25.    File</div></body></html>"; email.IsBodyHtml = true;
  26.    email.Body = body1 + body2 + body3;
  27.    SmtpClient Client = new SmtpClient("172.16.8.200");
  28.    try
  29.    {
  30.      Client.Send(email);
  31.    }
  32.    catch (Exception err)
  33.    {
  34.      Console.WriteLine(err.Message);
  35.    }
  36.    finally
  37.    {
  38.      email.Dispose();
  39.    }
  40. }
  41.  

Jun 27 '08 #4

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

Similar topics

2
by: Web Master | last post by:
Hi, I am having a little issue with Jacks Form mail php script. I have installed it and configured the form to get it to work, but for some bizarre reason I have 2 issues I can't seem to debug....
4
by: manatlan | last post by:
In an intranet/lan, i'd like to put a "python server script" (which run forever) on a computer A... On another computer B, I'd like to send smtp-email to the computer A ... (send to...
10
by: Peter Dragun | last post by:
I am generally new to programming under Unix, but know how to code under Windows. I have to create a simple program, that takes the following information from a file using redirection: 4 4 4 4 4...
4
by: tfsmag | last post by:
It acts like it sends, but nothing ever shows up... anything you guys can find glaringly wrong here? Thanks in advance, Jeff Here is the code that is supposed to send the mail. ...
4
by: k.visube | last post by:
In my ASP application,i need to send a formatted text mail (i.e with newline characters). here in my application i used a function in javascript which construts the mail body sample snippet ...
6
by: jerrygarciuh | last post by:
Hi folks, HELP!!!! My habitual use of mail() is causing me some grief. I am having slightly different results depending on the server I use but the gist is that mail() is returning 1, and I...
5
by: Robert Dufour | last post by:
I am trying to use framework 1.1 - stuck with it. to send emails from a windows form application. The email messages can have attachments, usually two and they can be either text or sounds (wav...
1
by: Nelliwinne | last post by:
I do not have proper excellence at php programming. I wrote below script after reading several articles. Anyway that form-to-mail script doesn't work. form action is connected to following code ...
14
by: Jeff | last post by:
I'm writing my php "form mail" script. Does mail do any checking for header injection in the "to" and "subject" parameters? CR and/or LF? It seems to me it easily could and should, but does it?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.