View Full Version : Sending an email from Vizard

01-22-2012, 11:08 AM
I have a script that asks the user to fill out a form with fields such as name, class, instructor,...
The script creates a text file with this information and stores it in a folder.I would like to automatically e-mail this text file when the script is over.
I am using the code below:

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.MIMEText import MIMEText

# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = open(file path+textFileName.txt, 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % file path+textFileName.txt
msg['From'] = 'xyz@abc.com'
msg['To'] = 'xyz@abc.com'

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP()
s.sendmail(me, [you], msg.as_string())

I am getting this error:

Traceback (most recent call last):
File "<string>", line 11, in <module>
File "C:\Users\Stephanie\Documents\Works1.py", line 72, in <module>
s = smtplib.SMTP('localhost')
File "C:\Program Files (x86)\WorldViz\Vizard4\bin\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "C:\Program Files (x86)\WorldViz\Vizard4\bin\lib\smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Program Files (x86)\WorldViz\Vizard4\bin\lib\smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Program Files (x86)\WorldViz\Vizard4\bin\lib\socket.py", line 571, in create_connection
raise err
socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions