Hello,
I'm not a programmer, so please bear with me. I'm using the following script with Python 2.6 to send emails with attachments from the command line.
#!/usr/bin/python
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os
import sys
GMAIL_USER = 'username@gmail.com'
GMAIL_PASSWD = "password"
RECIPIENT = "backup@gmail.com"
SUBJECT = "Document backup: " + sys.argv[2]
MESSAGE = "A backup version of an OpenOffice.org document is attached."
def mail(to, subject, text, attach):
msg = MIMEMultipart()
msg['From'] = GMAIL_USER
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(text))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part)
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(GMAIL_USER, GMAIL_PASSWD)
mailServer.sendmail(GMAIL_USER, to, msg.as_string())
mailServer.close()
mail(RECIPIENT, SUBJECT, MESSAGE, sys.argv[1])
The problem is that this script doesn't work with Python 3.0. I'd be grateful if someone could help me to fix the script, so it works with Python 3.0.
Thank you!
Kind regards,
Dmitri