Free Support Forum - aspose.com

FROM field display name's encoded length causes a FormatException

Hi,

I had to upgrade to v4.9.0.0 from v4.6.0.1 since BulkSend() fails silently in a Win 2008 IIS7 x64 environment with v4.6.0.1…

After upgrading, I started getting occasional FormatException errors: An invalid character was found in the mail header.

After much debugging, I believe the error is caused by the length of the encoded version of the FROM / TO display name.

Here’s a test code that clearly reproduces the problem. When using accentuated characters, the encoded length is longer that it appears at first. Depending on the encoding used, each accentuated character can result in 2, 3 or 4 quoted-printable or base64 characters. This explains why each encoding fails at a different moment…

I have never experienced this error with v4.6.0.1.

Attached are .eml files from 4.9.0.0 and 4.6.0.1. With 4.6.0.1, you’ll notice that even the longest display name works well…

Can you please provide a fix for this issue or a workaround? Obviously, this is quite urgent… sorry. :stuck_out_tongue:

Thank you,

Dominic.

----------------
Aspose.Network.License license = new Aspose.Network.License();
license.SetLicense(@“Aspose.Total.lic”);

const string toEmail = "me@domain.com";
const string fromEmail = "me@domain.com";

const string senderEmail = "noreply@domain.com";
const string senderDisplayName = “domain.com”;

const string smtpServer = “smtp.domain.com”;

/* NOT working with all encoding.
const string fromDisplayName = “This is a very long from string just to test if is not related only on the length of the display name”;
const string fromDisplayName = “1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890”;
const string fromDisplayName = “éèêëÉÈÊËàÀùüÙÜîïÎÏçÇéèêëÉÈ”;

// NOT working with Default encoding (works with ISO and UTF-8)
const string fromDisplayName = “éèêëÉÈÊËàÀùüÙÜîïÎÏçÇ”;
const string fromDisplayName = “éèêëÉÈÊËàÀùüÙÜ”;
const string fromDisplayName = “éèêëÉÈÊËàÀùü1234”;

// Working strings
const string fromDisplayName = “1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 123456789”;
const string fromDisplayName = “éèêëÉÈÊËàÀùü”;
const string fromDisplayName = “éèêëÉÈÊËàÀùüÙ”;
const string fromDisplayName = “éèêëÉÈÊËàÀùü123”;
*/

const string fromDisplayName = “éèêëÉÈÊËàÀùüÙÜîïÎÏçÇéèêëÉÈ”;

const string testString = “Étrangement, déjà ambiguë, à Montréal, je préfère haïr ce garçon.”;

string asmVersion = typeof(Aspose.Network.Mail.MailMessage).Assembly.GetName().Version.ToString();

Aspose.Network.Mail.MailMessage email;
Aspose.Network.Mail.SmtpClient client;

//ISO-8859-1
email = new Aspose.Network.Mail.MailMessage();
email.Sender = new Aspose.Network.Mail.MailAddress(senderEmail, senderDisplayName, System.Text.Encoding.GetEncoding(28591));

email.From = new Aspose.Network.Mail.MailAddress(fromEmail, fromDisplayName, System.Text.Encoding.GetEncoding(28591)); //ISO-8859-1 (Western ISO)
email.To.Add(new Aspose.Network.Mail.MailAddress(toEmail, fromDisplayName, System.Text.Encoding.GetEncoding(28591))); //ISO-8859-1 (Western ISO)

email.SubjectEncoding = System.Text.Encoding.GetEncoding(28591); //ISO-8859-1 (Western ISO)
email.Subject = "ISO-8859-1: " + testString;

email.BodyEncoding = System.Text.Encoding.GetEncoding(28591); //ISO-8859-1 (Western ISO)
email.TextBody = "ISO-8859-1: " + testString;

client = new Aspose.Network.Mail.SmtpClient(smtpServer);
client.Encoding = System.Text.Encoding.GetEncoding(28591); //ISO-8859-1 (Western ISO);
client.AuthenticationMethod = Aspose.Network.Mail.SmtpAuthentication.None;
client.Send(email);

email.Save(@“C:\temp\asposeNetworkTest03-v” + asmVersion + “-iso-8859-1.eml”);

// UTF 8 version
email = new Aspose.Network.Mail.MailMessage();
email.Sender = new Aspose.Network.Mail.MailAddress(senderEmail, senderDisplayName, Encoding.UTF8);

email.From = new Aspose.Network.Mail.MailAddress(fromEmail, fromDisplayName, Encoding.UTF8);
email.To.Add(new Aspose.Network.Mail.MailAddress(toEmail, fromDisplayName, Encoding.UTF8));

email.SubjectEncoding = Encoding.UTF8;
email.Subject = "UTF-8: " + testString;

email.BodyEncoding = Encoding.UTF8;
email.TextBody = "UTF-8: " + testString;

client = new Aspose.Network.Mail.SmtpClient(smtpServer);
client.Encoding = Encoding.UTF8;
client.AuthenticationMethod = Aspose.Network.Mail.SmtpAuthentication.None;
client.Send(email);
email.Save(@“C:\temp\asposeNetworkTest03-v” + asmVersion + “-utf-8.eml”);

// Default version
email = new Aspose.Network.Mail.MailMessage();
email.Sender = new Aspose.Network.Mail.MailAddress(senderEmail, senderDisplayName);

email.From = new Aspose.Network.Mail.MailAddress(fromEmail, fromDisplayName);
email.To.Add(new Aspose.Network.Mail.MailAddress(toEmail, fromDisplayName));

email.Subject = "Default: " + testString;

email.TextBody = "Default: " + testString;

client = new Aspose.Network.Mail.SmtpClient(smtpServer);
client.AuthenticationMethod = Aspose.Network.Mail.SmtpAuthentication.None;
client.Send(email);
email.Save(@“C:\temp\asposeNetworkTest03-v” + asmVersion + “-default.eml”);


Hi Dominic,

I have reproduced the bug using the code snippet above. Unfortunately, I cannot find any workaround for this issue. We will try to fix this as soon as possible. The issue ID is 14343. We will notify you when we fix this.

The issues you have found earlier (filed as 14343) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi!


This error does also occurs in version 2.2.0.0.

This error is also caused if there is a dot in the Name like “Dr. Max Mustermann”.


class Program
{
[STAThread]
static void Main(string[] args)
{
try
{
var asposeEmailLicence = new Aspose.Email.License();
asposeEmailLicence.SetLicense(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + “.Aspose.Total.lic”));

var mailAddressString =
“üüü üüü üüü üüüüüüüüüüüü üüüüüüüüüüü max.muster@musterland.com”;


var mail = new MailMessage(“Example example@example.com”,
mailAddressString,
“Teste deine Ümläute”,
“Teste Ümläüte sölänge dü künnst.”);

var filename = Path.ChangeExtension(Path.GetTempFileName(), “pms”);


Console.WriteLine(“Before Saving”);

mail.Save(filename);

mail.Dispose();

mail = null;

mail = MailMessage.Load(filename);

Console.WriteLine(“Loaded!”);

Console.ReadKey();

}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.ReadKey();
}
}
}

Thanks, Thomas.

Hi Thomas,


I am afraid to inform you that I was unable to reproduce this issue at my end with the latest version of Aspose.Email for .NET 2.3.0. Could you please download and try this version at your end and let us know your feedback? We will look into it further and assist you as soon as possible.

Hello Kashif!


Sorry for the delay!

I’ve tried to rerun my sample with the 2.3.0.0 version an still getting this error.

I’ve attached my sample.

Thanks, Thomas

Hi Thomas,


Thank you for the sample code.

I was able to reproduce the issue with the help of sample file you have provided and have logged it for further investigation by our development team under issue id: NETWORKNET-33524. I will update you here once there is any update in this respect, and appreciate your patience in this regard.

The issues you have found earlier (filed as NETWORKNET-33524) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.