Aspose.Email python module overwriting base python 'email' module

Hi support,

We are using Aspose.Email-for-Python-via-NET within python. When importing this package alongside the ‘email’ python base module, apose.email overwrites it, preventing the email module from being used. In particular, this prevents access to email.policy provided by python. Is there a way to resolve this issue?

Thank you

Hello @Sijo.Kolambran ,

Thank you for reporting your issue.

It seems like you are encountering a namespace collision issue between the email module in Python’s library and the Aspose.Email module.
When you import Aspose.Email, it might be overshadowing the email module, causing conflicts.

To solve this issue, you can access the email module functionality through the python_email alias, avoiding conflicts with the Aspose.Email module.

An example:

import email as python_email
from Aspose.Email import ...

policy = python_email.policy

Hi,

Unfortunately we are unable to implement this workaround as the email module is being imported from a 3rd party package and so it’s not feasible to edit. Are there other ways to prevent this issue?

Thanks again for your help

Hello @Sijo.Kolambran,

You might consider using the importlib module to dynamically import the Aspose.Email module and manipulate its behavior without directly importing it into your code. This allows you to control the namespace and avoid conflicts with the email module.

import importlib

# Dynamically import the Aspose.Email module with a custom name
aspose_email = importlib.import_module('aspose.email')

# Now you can use 'aspose_email' instead of 'email'
eml = aspose_email.MailMessage.load(file_name);

Hi,

Please let me know if I’m misunderstanding, but this approach doesn’t seem to avoid the base email module being overwritten:

import importlib

aspose_email = importlib.import_module('aspose.email')
print(aspose_email)

import email
print(email)

Output (The second import points to aspose.email):

<module 'email' (C:\...\lib\site-packages\aspose\email.cp39-win_amd64.pyd)>
<module 'email' (C:\...\lib\site-packages\aspose\email.cp39-win_amd64.pyd)>

So similarly, external modules will be affected by the overwrite.

@Sijo.Kolambran ,

Thank you for the provided information. Your issue is under investigation. We’ll let you know the results asap.