.NET or MSSMTP adding a line break in the From header

I can be just blind (very possible!), But I can not find any information here / google somewhere that helps me in general :(

First, below, the code that I use to send an email:

MailMessage newMM = new MailMessage(); newMM.To.Add(new MailAddress(userEmail)); newMM.From = new MailAddress(getFrom, getFromName); newMM.IsBodyHtml = true; newMM.Subject = userSubject; newMM.Body = userHTML; if (chkEncoding.Checked) { newMM.BodyEncoding = System.Text.Encoding.UTF8; newMM.SubjectEncoding = System.Text.Encoding.UTF8; } NetworkCredential basicAuthenticationInfo = new NetworkCredential(mUsername, mPassword); SmtpClient smtp = new SmtpClient(mServer); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = basicAuthenticationInfo; smtp.Send(newMM); 

Which sends a fine, and makes UTF8 a fine when turned on, etc .... however, in the email I receive this (UTF8 or not):

 ... MIME-Version: 1.0 From: "The name i want" < fromname@fromdomain.com > To: someone@atadomain.com ... 

And this is from checking files in the Queue MSSMTP folder, so it seems to me that .NET adds line breaks or MSSMTP does this when it receives an email.

Has anyone come across this before? or have any ideas? :)

The reason this is important is because Declude says that the address does not match and adds the spam weight that I see through the headers:

 X-RBL-Warning: FROMNOMATCH: Env sender ( fromname@fromdomain.com ) From: ("The name i want") mismatch. ... X-Declude-Tests: ... FROMNOMATCH [2] ... 

So, I think that other spam filters will also have an impact on themselves.

EDIT:

For reference; All emails look great in all email clients, it's just a problem with the processing of headers / spam.

If someone has free time, is it possible to send a message using .NET and check the original headers (unedited and not reviewed by the mail client) and tell me? I will continue shipping now :)

EDIT2:

I created a basic SMTP server in .NET using sockets, basic responses (220, 250, 354, etc.) and used the code to connect to it and send ... and the problem arises, so it is definitely on code /. NET, not MS-SMTP.

I also created a completely new application for Windows.NET 4.0, added a button and placed it in this code (note, I added the use of System.Net.Mail; at the top too, but nothing else from a clean new Windows application):

 private void button1_Click(object sender, EventArgs e) { MailMessage newMM = new MailMessage(); newMM.To.Add(new MailAddress(" toaddress@domain.com ")); newMM.From = new MailAddress(" fromaddress@domain.com ", "Happy As'Larry"); newMM.IsBodyHtml = true; newMM.Subject = "My Subject"; newMM.Body = "My HTML"; SmtpClient smtp = new SmtpClient("localhost"); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(newMM); } 

Please note that this is NOT edited in any way ... there is no need for verification as its local SMTP test output application, so it is exactly like it above.

My SMTP application uses the TcpListener and Socket objects from System.Net.Sockets and just prints all the deleted data in a simple text field, it parses the line for the command buffer so that it can actually respond and get the DATA command to verify that it sends .NET :)

The conclusion is here:

 EHLO WhiteDragon-PC MAIL FROM:< fromaddress@domain.com > RCPT TO:< toaddress@domain.com > DATA MIME-Version: 1.0 From: "Happy As'Larry" < fromaddress@domain.com > To: toaddress@domain.com Date: 28 Feb 2011 19:00:19 +1100 Subject: My Subject Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: quoted-printable My HTML . 

So, with 2 completely new applications, with very basic code in each of them, there is still a problem!

Is this a .NET 4.0 bug? if someone wants SMTP code, I will insert this too if you want to check this thing.

+4
source share
3 answers

Ok!

The last part of my editing displays the results.

Switch the test client application to .NET 3.5, and the from header:

From: "Happy As'Larry" < fromaddress@domain.com >

Switch the test client application to .NET 4.0, and the from header:

From: "Happy AsLarry"
< fromaddress@domain.com >

So this is a problem in / modifying the .NET 4.0 libraries, and now I have a solution ... change the profile to .NET 3.5!

Thanks to everyone who helped :)

EDIT: alignment and coding of tags ... heh

EDIT2: Also, it has fixed Declude headers for spam checking, the weight of NOFROMMATCH [2] is missing, so my letters are less than “spam”

My suggestion is that you are using .NET 4.0 and sending emails ... check this out!

+3
source

When comparing source code with similar source code in one of my projects, the only opportunity I came up with is this:

The getFrom variable contains a string.

0
source

The problem is that earlier versions of MailMessage contain many other errors; take a look at this topic: http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/879f13d7-24e6-4a0f-b396-627e9da25fc1/

So, if someone can offer a better class that doesn't rely on MailMessage, I would really appreciate it.

And for your pleasure, here is the Encode code in .NET 4.0 that messed up your email address:

 // Encodes the full email address, folding as needed internal string Encode(int charsConsumed) { string encodedAddress = String.Empty; IEncodableStream encoder; byte[] buffer; Debug.Assert(this.Address != null, "address was null"); //do we need to take into account the Display name? If so, encode it if (!String.IsNullOrEmpty(this.displayName)) { //figure out the encoding type. If it all ASCII and contains no CRLF then //it does not need to be encoded for parity with other email clients. We will //however fold at the end of the display name so that the email address itself can //be appended. if (MimeBasePart.IsAscii(this.displayName, false)) { encodedAddress = String.Format("\"{0}\"", this.displayName); } else { //encode the displayname since it non-ascii encoder = encoderFactory.GetEncoderForHeader(this.displayNameEncoding, false, charsConsumed); buffer = displayNameEncoding.GetBytes(this.displayName); encoder.EncodeBytes(buffer, 0, buffer.Length); encodedAddress = encoder.GetEncodedString(); } //the extra space is because there should be a non-printable whitespace char //following the fold (CRLF) and there is supposed to be a space between the display name and //the address so this is necessary. encodedAddress += "\r\n "; } //now we have the encoded display name (if present), we need to append the address to it. if (!String.IsNullOrEmpty(encodedAddress)) { //address should be enclosed in <> when a display name is present encodedAddress += SmtpAddress; } else { //no display name, just return the address encodedAddress = this.Address; } return encodedAddress; } 
0
source

Source: https://habr.com/ru/post/1341571/


All Articles