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

Free Support Forum - aspose.com

Exception "An invalid character was found" when passing string with dot and comma (Java)

Hi!

I’m getting an exception:

com.aspose.email.system.exceptions.FormatException: An invalid character was found in the mail header.

when passing string with dot and comma to “To” header:

MapiMessage message = new MapiMessage();
HeaderCollection headers = message.getHeaders();
String to = "qwerty.,string";
headers.add_(getTo().toString(), to);

It would also be very helpful, if you add the exact header and the exact invalid character to exception message, smth like:

com.aspose.email.system.exceptions.FormatException: An invalid character (,) was found in the mail header: qwerty.,string 

Thanks!

@Zeruch,

I have worked over your requirements and like to share that if you add “.,” together then exception is thrown. You may please make necessary correction to use any one of character in header.

An issue with ID EMAILJAVA-34519 has also been added as improvement in our issue tracking system to consider improving the error message on our end as per suggestion.

Hi @mudassir.fayyaz!

Thanks for the reply. Having both “.,” together is a possible combination in sender name in our project, so it would be very nice if you could fix that.

Thanks!

@Zeruch,

Sure, we will share good news with you soon.

Looks like the exception is thrown when recipient has trailing dot (".").
And when we pass “.,” it just splits it into 2 recipients with one having trailing dot.

Is it possible to escape comma somehow?

@Zeruch,

We are investigating this and will get back to you with good news with soon.