Select to view content in your preferred language

Python script that emails an attachement

1487
2
09-08-2014 07:56 AM
LouisEarly
Emerging Contributor

I had the following python script that sent out an email with an attachment.  It worked fine for the last 6 months then suddenly has stopped working.  Anyone have any ideas? 

import smtplib

from email.MIMEMultipart import MIMEMultipart

from email.MIMEBase import MIMEBase

from email.MIMEText import MIMEText

from email import Encoders

import zipfile

import os

gmail_user = "xxx@gmail.com"

gmail_pwd = "password"

def mail(recipients, subject, text, attach):

    msg = MIMEMultipart()

    msg['Subject'] =subject

    msg['From'] = gmail_user

    msg['To'] = ", ".join(recipients)

    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_pwd)

    mailServer.sendmail(gmail_user, recipients, msg.as_string())

    # Should be mailServer.quit(), but that crashes...

    mailServer.close()

mail(['xxx@williams.com'],

    "KMZ Update",

    "attached is the google earth update", r"C:\Users\user\Desktop\GEupdate.kmz")

Tags (2)
0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor

What is the error message, if any?

Edit: the above script works perfectly fine for me, as it is.

0 Kudos
LouisEarly
Emerging Contributor

Im not getting an error. The script just runs and nothing happens.  It simply says it's still running. 

0 Kudos