Mail Subject gets chopped

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
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". More debugging information: We do not reply to these system messages very often, but whenever we do, the header information (From, Sender, Date, Subject) all looks like it is in Chinese!

Here is what I am doing:
C#:
private bool SendMessage(string fcn)
{
  MailMessage email = new MailMessage(fcn, fcn);
  email.SubjectEncoding = Encoding.Unicode;
  email.BodyEncoding = Encoding.Unicode;
  email.Subject = string.Format("SystemID {0} - {1}", m_systemId, m_coil.SerialNumber);
  string fmt = "<html><body bgcolor={0}><div><h3>Coil {1}<br/><font color=\"red\">{2}</font> Approved Override For {3}</h3><hr><table border=1>";
  string body1 = string.Format(fmt, split.Panel1.BackColor.Name, m_coil.SerialNumber, m_dbase.Supervisor.FullName, m_dbase.Employee.FullName);
  string body2 = string.Empty;
  foreach (ListViewItem i in ListView1.Items)
  {
    if (i.ImageKey == "stop.ico")
    {
      body2 += string.Format("<tr><td>{0} Issue:</td><td><b><font color=\"green\">{1}</font></b></td></tr>", i.SubItems[0].Text, i.SubItems[1].Text);
    }
  }
  if (0 < body2.Length)
  {
    string body3 = "</table><hr></div><div>End Of File</div></body></html>";
    email.IsBodyHtml = true;
    email.Body = body1 + body2 + body3;
    SmtpClient Client = new SmtpClient("172.16.8.200");
    try
    {
      Client.Send(email);
    }
    catch (Exception err)
    {
      Console.WriteLine(err.Message);
    }
    finally
    {
      email.Dispose();
    }
  }
}
If someone can catch it, I would sure appreciate knowing what I'm doing wrong.
 
It looks like the encoding could be the problem, however I honestly couldn't say why.

Have you tried setting the encoding to UTF8 to see if that makes a difference?
 
Thanks Plausibly! Your hint provided enough insite for me to troubleshoot around enough to find a solution. Instead of the code I was using above, I'm using this instead:
C#:
private bool SendMessage(string fcn)
{
  string fcn = "[EMAIL="Failed_Coil_Notify@Aaon.com"]Failed_Coil_Notify@Aaon.com[/EMAIL]";
  string subject = string.Format("SystemID {0} - {1}", m_systemId, m_coil.SerialNumber);
  string message = "This message is formatted for HTML only.";
  MailMessage email = new MailMessage(fcn, fcn, subject, message);
  string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
  body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
  body += string.Format("</HEAD><BODY bgcolor={0}><DIV><FONT face=Arial size=2>", split.Panel1.BackColor.Name);
  string fmt = "<div><b>Coil {0}: {1} Approved Override For {2}</b><hr><table border=1>";
  body += string.Format(fmt, m_coil.SerialNumber, m_dbase.LeadSuper.FullName, m_dbase.Employee.FullName);
  string body2 = string.Empty;
  foreach (ListViewItem i in ListView.Items)
  {
    if (i.ImageKey == "stop.ico")
    {
      body2 += string.Format("<tr><td>{0} Issue:</td><td><b><font color=red>{1}</font></b></td></tr>", i.SubItems[0].Text, i.SubItems[1].Text);
    }
  }
  body += body2;
  body += "</table><hr></div><div>End Of File</div></FONT></DIV></BODY></HTML>";
  email.IsBodyHtml = true;
  email.Body = body;
  SmtpClient Client = new SmtpClient("172.16.8.200");
  Client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
  try {
    Client.Send(email);
    return true;
  } catch (Exception err) {
    Console.WriteLine(err.Message);
    return false;
  } finally {
    email.Dispose();
  }
}
 
Back
Top