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

Free Support Forum - aspose.com

How to create MapiAttachment? How to bypass address validation?

Hi there,

We want to use your product to create message. (not converted from existing message).
And run into some issues:
1. It tried to validate the address and throw exception if the address is invalid.
But we want to allow invalid address. How to bypass the address validation check?

2. We want to create MapiMessage, then store it to PstFile. But could not find a way to create MapiAttachment. What’s the best approach to create MapiAttachment?

3. There were some encoding issue. For example:
msg.getHeaders().add(“to”, MimeUtility.encodeText(“some special chars”));
The text shown in outlook’s To column is wrong. If we click on it, the popup window show the text correctly.

Any suggestion?



Hi Billow,

Thank you for writing to Aspose support team.

  1. Email address validity is one of the requirements for creating messages. The address should be in proper SMTP format or Exchange format in order to work it out and can’t be bypassed. Could you please share which type of addresses you want to bypass?
  2. You can create a MapiMessage and add attachments to it as shown in the following sample code.
MapiMessage mapi = new MapiMessage();
Path path = Paths.get("path/to/file");
mapi.getAttachments().add("DesertP.jpg", Files.readAllBytes(path));

3. Could you please provide us with some sample code or file that can be used to reproduce this issue at our end? We'll investigate it to assist you further in this regard.

Please let us know if we can be of any additional help to you in this regard.

Thanks for your reply.
Basically, we want to convert some EML files to MSG files, then store them in PST file. So we want to keep the original format as close as possible. It’s very common for EML files to have invalid address. It could be in any malformed format. So if we validate them, then those invalid addresses will be dropped.

For the encoding issue, when I am using is:
Option 1:
mailMsg.getHeaders().add(“to”, MimeUtility.encodeText("“测试中文”") + " abc@abc.com");
Option 2:
MailAddressCollection addressCol = new MailAddressCollection();
addressCol.addMailAddress(new MailAddress("to@domain.com", “测试中文”));

Both of them set the correct header:
To: =?utf-8?B?5rWL6K+V5Lit5paH?= to@domain.com

I imported the PST file to outlook.
And when I view the message, it’s shown: To: ???

If I double check on the To field, the popup box will display:
Display Name: 测试中文
E-mail address: to@domain.com

Don’t know why it’s shown ??? there.
I had the same 测试中文 in subject which displayed just fine.

Also, do you provide JAVA source code for licensed client? Or will you willing to sell source code for extra charge?

Hi Billow,

Thank you for providing the feedback.

With respect to your query of email address validation, could you please provide us with the sample EML files that contain such email addresses? We’ll need it for further investigation at our end.

Regarding the encoding issue, the characters you are mentioning are actually Unicode and during conversion from MailMessage to MapiMessage, the Unicode flag format needs to be included. Please have a look at the following code sample which shows how to create such PST and let us know your feedback.

Sample Code:

MailMessage mailMsg = new MailMessage();

mailMsg.setSubject("test Subject");

mailMsg.setBody("test Body");

mailMsg.setFrom(new MailAddress("abcgmail@.com"));

MailAddressCollection addressCol = new MailAddressCollection();

addressCol.addMailAddress(new MailAddress("toAddress@domain.com", "测试中文"));



MapiMessage mapiMsg = MapiMessage.fromMailMessage(mailMsg,MapiConversionOptions.getUnicodeFormat());

PersonalStorage pst = PersonalStorage.create("Email_589113.pst", FileFormatVersion.Unicode);

FolderInfo tmpFolder = pst.createPredefinedFolder("Inbox", StandardIpmFolder.Inbox);



Thanks, the setting worked!

So how about the question on address validation.
Is it possible to bypass the format check and allow any address, even its invalid?

When we convert EML to MSG then add to PST, we want to make sure that the user saw the same info in EML client and MSG client. If the invalid address was filtered, then it will be a problem.



BTW, we tried aid4mail and other api which can convert EML to MSG format.
They can keep malformed addresses. And outlook can view those MSG without any issue. So we believe that the address check is not a must.
This feature is blocking us from selecting your product.
Is it possible to add a switch to ignore the check?

Hi Billow,

Can you please share a sample EML file having such a mlaformed address? We need the sample file to investigate the issue at our end for assisting you further. It will be better if you create a new Post on the forum (though it is not must) with your sample EML file and code that you are using for conversion. It will help isolate the issue from the other one and enable us to assist you in a better manner.