How to install email python module in ArcGIS Pro environment to use with Python 3.x?

6022
4
Jump to solution
10-06-2017 03:24 AM
PaulHaakma
Regular Contributor

Hi all

I have a script that I used for sending emails from ArcMap using python 2.x. It uses all the import statements below. When I try to use the same script in ArcGIS Pro as a script (using python 3.x), it says: ImportError: No module named 'email.MIMEMultipart'.

Using the 'package manager' in ArcGIS Pro itself, I can't see any module called 'email' that I can import. Can anyone tell me how I can add that module to the ArcGIS Pro python environment, or whether I need to find some way to re-write my script without that module. Or can anyone suggest an alternate module that can do the same tasks?

import arcpy
import smtplib, os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from email.Utils import COMMASPACE, formatdate
from email import Encoders
import ConfigParser

msg = MIMEMultipart('mixed')

msg['From'] = send_from
msg['To'] = send_to if isinstance(send_to, basestring) else COMMASPACE.join(send_to)

etc etc...

cheers

-Paul

0 Kudos
1 Solution

Accepted Solutions
MattiasWallin
New Contributor II

Paul,

Try this instead:

from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.utils import formatdate
COMMASPACE = ', '
from email import encoders

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Paul,

I would take a look at some of the example from the Python 3.x help:

19.1.8. email: Examples — Python 3.6.3 documentation 

You can compare these examples to that of Python 2.x:

18.1.11. email: Examples — Python 2.7.14 documentation 

PaulHaakma
Regular Contributor

Thanks Jake

I was focusing on the wrong thing - I was thinking there was something wrong with my python environment, when, as you point out, I hadn't read the documentation closely enough to realise there were those differences in the import statements required between python v2 and v3.

Mattias below helped with the exact import statements to use.

Cheers,

-Paul

0 Kudos
MattiasWallin
New Contributor II

Paul,

Try this instead:

from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.utils import formatdate
COMMASPACE = ', '
from email import encoders

PaulHaakma
Regular Contributor

Thanks Mattias

Yes those worked. Thanks for the help.

cheers,

-Paul

0 Kudos