VB.NET generated email subject line contains tabs where spaces should be in Outlook 2007

Posted on 2009-12-18
Last Modified: 2012-05-08
Dim mail As New MailMessage
mail.Subject = BuildSubject(newsData)
mail.Body = "<table></table>"
mail.IsHTML = True
'Some other code

Dim smtp As New SmtpClient(_sMTPServer)
smtp.Port = 25

    Private Function BuildSubject(ByRef newsData As News) As String
        Dim subject As New StringBuilder

        subject.Append("ALERT - ")
        subject.Append(" Traveller" & CStr(IIf(newsData.PassengerCount > 1, "s", "")))
        subject.Append(" present in ")
        subject.Append(" - Incident level: " & newsData.IncidentLevel.ToString())
        subject.Append(" - Category: " & newsData.FullCategories)
        subject.Append(" - ")
        subject.Append(" - ")

        Return subject.ToString
    End Function

When email is received in Outlook 2007 contains the following (note there is a tabl before 'strike' and before 'category'):
ALERT - 5 Travellers present in United Kingdom - Incident level: 2 -      Category: Rail Delays/Disruption - UK: Eurostar running 'normally' despite      strike - Proximity

Please help me in what is causing this and how to I get rid of this. Is this to do with Outlook, the email body text not having html tags or is this due to the colons in the subject line?
Question by:TheAnvilGroup
    LVL 10

    Expert Comment

    When you look at the string while debugging in VB.NET, do you have the tabs also?  If so, then you can replace them with

    Return subject.ToString().Replace(Chr(9), " "c)
    LVL 1

    Author Comment

    There are no tabs in the string, I pasted the string into a hex editor and no 09 (tabs) appeared. I only recieve the tabs (09) when the email is in the Outlook 2007 outbox. The problem is that the spaces are being converted to tabs for some unknown reason.
    LVL 10

    Expert Comment

    I've been searching in Google for a while.  This seems to be a problem with a lot of email-clients, not just Outlook.  It only happens for long subject lines.

    Also, In Outlook 2007, under Tools, Options, Mail Format (tab), Internet Format ... (button)
    there is an option for automatic wrapping in plain text messages.  Maybe this setting has something to do with it?  The default wrapping length seems to be 76 characters.  
    LVL 1

    Author Comment

    The tabs appear a character position 69 and then counting from this position another 71 characters. Knowing this how to I solve this other than changing the email client configuration.
    LVL 10

    Accepted Solution

    If it is the email client that converts the last space character into a linefeed + tab character, then you will have to change it's configuration.

    Or try to limit the length of the subject line?
    LVL 1

    Author Closing Comment

    Will check setting on Exchange server and some other applications are also effected and the Exchange server was recently upgraded.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now