Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

Sending Emails from SMTP server requiring AUTHENTICATION with Python Code tool


Thanks @WillBowman  for this awesome solution!  


This is awesome! @DavidM  @WillBowman 

Alteryx Partner

Something really weird going on here .... when I install the package the macro doesn't show up at all :( 


In the end I had to copy the contents of the macro to a brand new workflow and then it worked fine.




That is certainly weird. With 2019.1? or an earlier version?

Alteryx Partner

Yeah, 2019.1.6  VERY crazy but I got it working.  I now have a VERY impressed client :) 


Nicee. Just a word of warning, the python tool (read: this macro) has failure potential when used in macros.


This error occurs when the macro is called simultaneously by separate workflows. If there are 10 workflows with the macro that are scheduled to run at the same time, some may fail.


This is because Alteryx runs everything python through jupyter (even in production mode... yeah they kind of stretched the truth a little on that one) and jupyter locks certain files when it runs the code.


I haven't actually seen this error in my logs for a while but that may be because I moved most of my error reporting to airflow :/



Hello @WillBowman,

Thank you very much for the Macro!

I just have a little trouble when I want to send with an attachment, I find the email in "Sent item" but nothing in the "Inbox" of the recipient.

Sending without an attachment works perfectly.

I have the version of the macro with the correction: c ['Attachment Path'] replaced by e ['Attachment Path'].

Do you know where this error might come from?




I was looking for a solution to separate data based on user name and then send Excel files out to those users. The Excel file needed to be based on a template and the email need to be HTML. I was able to get that working by leveraging WillBowman's macro. I have attached it here in case someone is trying to do the same thing. 


Hi @DavidM ,


I am getting below error. I'd highly appreciate if you could suggest on how to resolve this issue.


A few changes that  I made:

I am using .jpg instead of .pdf from my local computer with File Path: "C:\Users\ID\desktop\imag.jpg" and have made changes accordingly

attach = email.mime.application.MIMEApplication(,_subtype="jpg")

"fromaddr" is my company email id and "pwd" is company login password 




OSError                                   Traceback (most recent call last)
<ipython-input-2-31f883d1e9bb> in <module>
     56 # Establish the server connection, send extended HELO, use TLS and login with pwd, then send the email
---> 57 server = smtplib.SMTP(server_url, 25)  # Change the ports for SMTP as needed
     58 server.connect(server_url,587)         # Change the ports for secure connection as needed
     59 server.ehlo()

C:\Program Files\Alteryx\bin\Miniconda3\lib\ in __init__(self, host, port, local_hostname, timeout, source_address)
    250         if host:
--> 251             (code, msg) = self.connect(host, port)
    252             if code != 220:
    253                 raise SMTPConnectError(code, msg)

C:\Program Files\Alteryx\bin\Miniconda3\lib\ in connect(self, host, port, source_address)
    333         if self.debuglevel > 0:
    334             self._print_debug('connect:', (host, port))
--> 335         self.sock = self._get_socket(host, port, self.timeout)
    336         self.file = None
    337         (code, msg) = self.getreply()

C:\Program Files\Alteryx\bin\Miniconda3\lib\ in _get_socket(self, host, port, timeout)
    304             self._print_debug('connect: to', (host, port), self.source_address)
    305         return socket.create_connection((host, port), timeout,
--> 306                                         self.source_address)    307 
    308     def connect(self, host='localhost', port=0, source_address=None):

C:\Program Files\Alteryx\bin\Miniconda3\lib\ in create_connection(address, timeout, source_address)
    721     if err is not None:
--> 722         raise err
    723     else:
    724         raise error("getaddrinfo returns an empty list")

C:\Program Files\Alteryx\bin\Miniconda3\lib\ in create_connection(address, timeout, source_address)
    711             if source_address:
    712                 sock.bind(source_address)
--> 713             sock.connect(sa)
    714             return sock

OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions





Hi @Shivam,


As far as i remember from my previous life as a developer this could be down to an application occupying that process. Focus on that last line of the error code and try to google some posts on stackoverflow. They are basically suggesting a few things to check.


Another thing could be that your networking setup does not allow these calls.


Hope this helps you in a direction to approach this.



David Matyas
Sales Engineer