0

This is weird! I'm trying to send an email using MailMessage through an SmtpClient and I'm getting some strange results! Here's what's going on: 1) This works on some emails but not on others. 2) I've narrowed it down to some problems with some subjects (work) and not others (don't work). For example - a subject of 'Lease has been approved by the land.' works. It's exactly 36 chars long. - a subject of 'Landlord approved lease. ' does not work even though it's exactly 36 chars long. - a subject of 'Landlord approved lease.............' does work. It's exactly 36 chars long.

Why is the Subject sooooo picky?

I pull the subject lines from a database table. The columns are formatted as an nchar(100) nullable. I Trim() each string before I assign it to the subject line so the width shouldnt make a difference. Any clues anyone?!

Thanks

stevekershaw
  • 155
  • 1
  • 5
  • 15
  • What doesn't work (what error)? Please you include your send mail function. I suspect the length of your subject is not the culprit. – MikeSmithDev Feb 12 '13 at 22:53
  • You may need to set the [SubjectEncoding](http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.subjectencoding.aspx), but without knowing exactly what error you're getting it's impossible to say. – Jason Feb 12 '13 at 22:58
  • have you tried with a local smtp development server like smtp4dev – Daniel Powell Feb 12 '13 at 23:10
  • There was no error... It just didn't work! – stevekershaw Feb 12 '13 at 23:54
  • mMailMessage.Subject = strSubject; mMailMessage.Body = strBody; mMailMessage.IsBodyHtml = true; mMailMessage.Priority = MailPriority.Normal; // Send the message. SmtpClient mSmtpClient = new SmtpClient(strHost); mSmtpClient.Send(mMailMessage); – stevekershaw Feb 12 '13 at 23:56
  • Here's how that mMailMessage is instantiated. MailMessage mMailMessage = new MailMessage { From = new MailAddress(strFrom) }; – stevekershaw Feb 12 '13 at 23:58
  • I can't use a local smtp development server because I must use the companies smtp server. – stevekershaw Feb 12 '13 at 23:59
  • Works: mailMessage.Subject = (string)(" landlord approved lease branch sessions.").Replace('\r', ' ').Replace('\n', ' '); – stevekershaw Feb 13 '13 at 01:00
  • Does not work: mailMessage.Subject = (string)(" landlord approved lease.").Replace('\r', ' ').Replace('\n', ' '); The only difference between these two is the 'Subject' string that works has an appended " branch sessions" at the end. Take that away and no email is sent out. – stevekershaw Feb 13 '13 at 01:03
  • If you're not getting an error the problem is likely happening on the server. You should check the SMTP logs, or possibly check if your "from" account is receiving any bounce back messages from the server. – Jason Feb 13 '13 at 03:11
  • No bounce back messages and I'm looking into the SMTP server logs now... It takes our IT department some time on these things. Thanks! – stevekershaw Feb 13 '13 at 19:22
  • This is just weird! I GIVE UP!! – stevekershaw Feb 13 '13 at 22:49

0 Answers0