We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception processing email attachments


We are getting exceptions when processing email attachments that filenames contain double single quotes at the end (test’’.txt). The exception occurs when the Attachment.Name setter is invoked. The StackTrace appears to indicate the offending filename is resulting in an attempted to find the strings encoding. Double single quotes in the middle of the filename do not cause the exception. Apose.Email for .NET 4.0 version

scrubbedName = FileAndPathNameIllegalCharUtility.CreateSafeFileName(att.Name, out scrubbedName, scrubOptions);

if (scrubbedName.IsNotNullOrEmpty())


att.Name = scrubbedName; //Exception here

//Good attachment name add to a list for processing


Characters removed by CreateSafeFileName (URI_ILLEGAL_CHARS = { ‘@’, ‘"’, ‘$’, ‘&’, ‘:’, ‘<’, ‘>’, ‘{’, ‘}’, ‘[’, ‘]’,
‘#’, ‘%’, ‘/’, ‘;’, ‘=’, ‘?’, ‘\’, ‘^’, ‘|’, ‘~’, ‘’’, ‘"’ };


System.Globalization.EncodingTable.internalGetCodePageFromName(String name)<o:p></o:p>


System.Globalization.EncodingTable.GetCodePageFromName(String name)<o:p></o:p>


System.Text.Encoding.GetEncoding(String name)<o:p></o:p>













Aspose.Email.Mail.Attachment.set_Name(String value)<o:p></o:p>


Hyland.Core.SubscriptionServer.Module.CheckForAttachment(MailMessage message,

List`1 attachments, IllegalCharacterScrubOptions scrubOptions) in



Thank you,

Hi Cameron,

Thank you for your inquiry and sharing details.

This is to update you that we have tried to reproduce the issue at our end with the help of information you shared. We are unable to reproduce the issue. Please use the latest version of Aspose.Email for .Net and try again. In case the issue persists, forward the sample project along with details to further look into the issue.

Hi Ikram,

Thank you for the reply. Unfortunately going to did not correct the issue. Please see the attached sample code that produces the error.

Hi Cameron,

Thank you for sharing sample project.

This is to update you that we have evaluated the scenario. We used our own server for testing as we were unable to connect to yours. Investigation shows that the sample code is working as expected. We have made a slit change in your code. Following is the new version of the code. Please try this at your end and update us with your feedback.


Aspose.Email.Clients.Imap.ImapClient _client = new Aspose.Email.Clients.Imap.ImapClient("xxxx", 993, "xxxx", "xxxx", Aspose.Email.Clients.SecurityOptions.SSLImplicit);
Aspose.Email.Clients.Imap.ImapQueryBuilder imapBuilder = new Aspose.Email.Clients.Imap.ImapQueryBuilder();
Aspose.Email.Tools.Search.MailQuery _query = imapBuilder.GetQuery();
Aspose.Email.Clients.Imap.ImapMessageInfoCollection messageInfos = null;
messageInfos = _client.ListMessages(_query);

Aspose.Email.MailMessage message = null;
if (messageInfos.Count > 0)
for (int i = 0; i < messageInfos.Count; i++)
Aspose.Email.Clients.Imap.ImapMessageInfo info = messageInfos[i];
message = _client.FetchMessage(info.SequenceNumber);
foreach (Aspose.Email.Attachment att in message.Attachments)
att.Name = @"output''.txt"; //Exception generated here


Aspose.Email.MailMessage msg = new Aspose.Email.MailMessage("user@domain1.com", "user@domain2.com", "test subject 3", "test message for 3");
Aspose.Email.Attachment attachment;
attachment = new Aspose.Email.Attachment(@"..\output''.txt");
_client.AppendMessage(_client.CurrentFolder.Name, msg);


Prefacing the string with the @ does not stop the exception. May I ask if your test email contained an attachment with a filename the ends in double single quotes. The exception I am getting references the attachment name not the new name being applied. I can access the filename via (string filename = att.Name) but the call to att.Name = @“output’’.text” generates an exception that references the attachments original name as it appears in the email. TestOneTwo’’.txt it the name of the file as it was attached to the message then sent. As the exception below points out.

System.ArgumentException {"‘TestOneTwo’ is not a supported encoding name. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.\r\nParameter name: name"}
This is an Exchange 2016 email server.

Thank you,

Hi Cameron,

I have checked the sample code and applied different attachment names containing double single quote at the end, middle and start. It is observed that in all the cases, exception is raised. Could you please confirm, if you are facing the same issue or not? Once the feedback is received, we will discuss the issue here in detail.

Hi Kashif,

Yes I can confirm that is what we are experiencing.

Thank you,

Hi Cameron,

Thank you for providing the feedback.

This issue is logged under Id:EMAILNET-38709 for further investigation by the product team. You will be automatically notified once any update is received in this regard.

Thank you Kashif

You are welcome.

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

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.