How to Solve NameError: name 'EmailMessage' is not defined -- email

Solution: Import the 'EmailMessage' module

To Solve the error, add the following line to the top of your code.

from email.message import EmailMessage

 

For more information:
Python email EmailMessage