Hello,
I am trying to set up an email function that will email the last 15 lines of a results.txt file in python. I am not sure how to do this and was asking do I have to connect to an email server or does python have some other way of sending email. The code below is what i have got so far and any help would be appreciated. Thanks
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = open('/home/build/result.txt', 'r')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()
me = '[email protected]'
you = '[email protected]'
msg['Subject'] = 'The contents of %s' % '/home/build/result.txt'
msg['From'] = me
msg['To'] = you
# 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())
s.quit()
Hello again,
When I'm trying to connect the server will not connect. I know I should not enter the email address. Can anyone suggest what way to write the host information. Thanks
smtplib.SMTPServerDisconnected: please run connect() first