Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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.

Posted

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:

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();
 }
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...