smtprelay text formatting issue

M

Mike Senkpiel

I have stumbled accross an odd issue while sending an email
programmatically from VS 2005. The following code is what I use to
reproduce the problem from a console app.

using System.Net.Mail;

static void Main(string[] args)
{
StringBuilder body = new StringBuilder();

body.AppendLine("1. Enable Midsession Level 1 Maintenance");
body.AppendLine("2. Enable Midsession Level 2 Maintenance");
body.AppendLine("3. Enable Midsession Level 3 Maintenance");

MailMessage email = new MailMessage("(e-mail address removed)",
"(e-mail address removed)", "Test", body.ToString());
new SmtpClient("smtprelay.whatever.com").Send(email);
}

This code results in the following email body.

1. Enable Midsession Level 1 Maintenance 2. Enable Midsession Level
2 Maintenance 3. Enable Midsession Level 3 Maintenance

But if any character is removed from the first line, e.g. "1. Enable
Midsession Level 1 Maintenanc", the result is:

1. Enable Midsession Level 1 Maintenanc
2. Enable Midsession Level 2 Maintenance 3. Enable Midsession Level
3 Maintenance

Same for the second line (now "1. Enable Midsession Level 1
Maintenanc" and "2. Enable Midsession Level 2 Maintenanc"):

1. Enable Midsession Level 1 Maintenanc
2. Enable Midsession Level 2 Maintenanc
3. Enable Midsession Level 3 Maintenance

There appears to be a 39 charcter limit before the unexpected behavior
occurs.

Can anyone reporoduce and/or explain this behavior?

Thanks,
Mike
 
M

Mike Senkpiel

I have stumbled accross an odd issue while sending an email
programmatically from VS 2005. The following code is what I use to
reproduce the problem from a console app.
using System.Net.Mail;
static void Main(string[] args)
{
    StringBuilder body = new StringBuilder();
    body.AppendLine("1. Enable Midsession Level 1 Maintenance");
    body.AppendLine("2. Enable Midsession Level 2 Maintenance");
    body.AppendLine("3. Enable Midsession Level 3 Maintenance");
    MailMessage email = new MailMessage("(e-mail address removed)",
"(e-mail address removed)", "Test", body.ToString());
    new SmtpClient("smtprelay.whatever.com").Send(email);
}
This code results in the following email body.
    1. Enable Midsession Level 1 Maintenance 2. Enable Midsession Level
2 Maintenance 3. Enable Midsession Level 3 Maintenance

 > [...]

You should post the _actual_ email body that is sent, and preferably the
whole thing (including headers).  That is, the full, verbatim text that
is sent (and received) as the representation of the email message.

The above is at best assumable to be the email body as interpreted by
some email program, and probably isn't even really that (since you
appear to have indented the text for the newsgroup message).  Maybe it's
exactly what's found in the email body, maybe it's not.  Part of
diagnosing the issue would involve showing the exact raw email message,
both in the scenario where it behaves as you want it to and in the one
where it doesn't.

Pete- Hide quoted text -

- Show quoted text -

Sorry, I should have mentioned that in VS, the body text is as it
should be, i.e. in the immediate window, I get:

?body
{1. Enable Midsession Level 1 Maintenance
2. Enable Midsession Level 2 Maintenance
3. Enable Midsession Level 3 Maintenance
}
Capacity: 160
Length: 126
MaxCapacity: 2147483647

And in the immediate window, the email is:

{System.Net.Mail.MailMessage}
AlternateViews: Count = 0
Attachments: Count = 0
Bcc: Count = 0
Body: "1. Enable Midsession Level 1 Maintenance\r\n2. Enable
Midsession Level 2 Maintenance\r\n3. Enable Midsession Level 3
Maintenance\r\n"
BodyEncoding: {System.Text.ASCIIEncoding}
CC: Count = 0
DeliveryNotificationOptions: None
From: {[email protected]}
Headers: {System.Net.Mime.HeaderCollection}
IsBodyHtml: false
Priority: Normal
ReplyTo: null
Sender: null
Subject: "Test"
SubjectEncoding: null
To: Count = 1

Outlook is the program through which the users of the application will
receive the email.
From there, I receive

1. Enable Midsession Level 1 Maintenance 2. Enable Midsession Level 2
Maintenance 3. Enable Midsession Level 3 Maintenance

I don't have a real-life example of how I want it to behave, but
basically, I want this:

1. Enable Midsession Level 1 Maintenance
2. Enable Midsession Level 2 Maintenance
3. Enable Midsession Level 3 Maintenance

Thanks for your help.
 
M

Mike Senkpiel

[...]
Outlook is the program through which the users of the application will
receive the email.
 From there, I receive
1. Enable Midsession Level 1 Maintenance 2. Enable Midsession Level 2
Maintenance 3. Enable Midsession Level 3 Maintenance

Sorry, I may not have been clear enough.

By "actual email body that is sent" what I really mean is the body that
is verified to have gone out through the network.  You can either sniff
the message as it goes out (e.g. using Wireshark or similar), or you can
look at the raw message source in your email program that receives the
message (less reliable than using a network sniffer, but is usually
accurate).

Your description above is apparently an attempt to convey how the
message looks to you in the email program, but the only thing that
matters is the _actual_ raw message source, which is practically
guaranteed to not actually look like that (most likely it will be a MIME
format, like text/plain, possibly also with a Content-Transfer-Encoding
of "quoted-printable").

I can look at the code and confirm that the string is as you intended it
before the message is sent, simply because I know that .NET's string
functions are reliable.  The real question is who is messing with your
message body, and at what stage of delivery.

Pete

Thanks Peter,

It's clear to me with your help that Outlook is removing what it
consideres to be _extra_ line breaks.
It would be ideal if I can find a way to make it stop from code, e.g.
sending the line breaks in a way that Outlook does not consider them
to be extras.
For now as I have spent enough time on this, I will just add an actual
extra line break as Outlook then honors both:

1. Enable Midsession Level 1 Maintenance

2. Enable Midsession Level 2 Maintenance

3. Enable Midsession Level 3 Maintenance

Thanks again for your help,
Mike
 
M

Mike Senkpiel

On 9/21/11 8:37 AM, Mike Senkpiel wrote:
[...]
Outlook is the program through which the users of the application will
receive the email.
 From there, I receive
1. Enable Midsession Level 1 Maintenance 2. Enable Midsession Level 2
Maintenance 3. Enable Midsession Level 3 Maintenance
Sorry, I may not have been clear enough.
By "actual email body that is sent" what I really mean is the body that
is verified to have gone out through the network.  You can either sniff
the message as it goes out (e.g. using Wireshark or similar), or you can
look at the raw message source in your email program that receives the
message (less reliable than using a network sniffer, but is usually
accurate).
Your description above is apparently an attempt to convey how the
message looks to you in the email program, but the only thing that
matters is the _actual_ raw message source, which is practically
guaranteed to not actually look like that (most likely it will be a MIME
format, like text/plain, possibly also with a Content-Transfer-Encoding
of "quoted-printable").
I can look at the code and confirm that the string is as you intended it
before the message is sent, simply because I know that .NET's string
functions are reliable.  The real question is who is messing with your
message body, and at what stage of delivery.

Thanks Peter,

It's clear to me with your help that Outlook is removing what it
consideres to be _extra_ line breaks.
It would be ideal if I can find a way to make it stop from code, e.g.
sending the line breaks in a way that Outlook does not consider them
to be extras.
For now as I have spent enough time on this, I will just add an actual
extra line break as Outlook then honors both:

1. Enable Midsession Level 1 Maintenance

2. Enable Midsession Level 2 Maintenance

3. Enable Midsession Level 3 Maintenance

Thanks again for your help,
Mike- Hide quoted text -

- Show quoted text -

I found a work around.
Link: http://stackoverflow.com/questions/...y-line-breaks-and-screwing-up-my-email-format
 
M

Mike Senkpiel

[...]
Outlook is the program through which the users of the application will
receive the email.
 From there, I receive
1. Enable Midsession Level 1 Maintenance 2. Enable Midsession Level 2
Maintenance 3. Enable Midsession Level 3 Maintenance

Sorry, I may not have been clear enough.

By "actual email body that is sent" what I really mean is the body that
is verified to have gone out through the network.  You can either sniff
the message as it goes out (e.g. using Wireshark or similar), or you can
look at the raw message source in your email program that receives the
message (less reliable than using a network sniffer, but is usually
accurate).

Your description above is apparently an attempt to convey how the
message looks to you in the email program, but the only thing that
matters is the _actual_ raw message source, which is practically
guaranteed to not actually look like that (most likely it will be a MIME
format, like text/plain, possibly also with a Content-Transfer-Encoding
of "quoted-printable").

I can look at the code and confirm that the string is as you intended it
before the message is sent, simply because I know that .NET's string
functions are reliable.  The real question is who is messing with your
message body, and at what stage of delivery.

Pete

I found a work around.
Link: http://stackoverflow.com/questions/...y-line-breaks-and-screwing-up-my-email-format
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top