|
@@ -0,0 +1,42 @@
|
|
|
+import smtplib
|
|
|
+import traceback
|
|
|
+import os
|
|
|
+from email.mime.text import MIMEText
|
|
|
+from email.mime.image import MIMEImage
|
|
|
+from email.mime.multipart import MIMEMultipart
|
|
|
+
|
|
|
+#gmail_user = 'jared@choozmo.com'
|
|
|
+#gmail_password='iofslyaiecoyxjot'
|
|
|
+gmail_user = 'edm@choozmo.com'
|
|
|
+gmail_password='wqdsyqwvppmubitv'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+sent_from = gmail_user
|
|
|
+to = ['jeweiliang@gmail.com']
|
|
|
+img_data=None
|
|
|
+with open('c:/tmp/coupon.png', 'rb') as f:
|
|
|
+ img_data = f.read()
|
|
|
+
|
|
|
+msg = MIMEMultipart()
|
|
|
+msg['Subject'] = '幸福空間五萬裝修折價券'
|
|
|
+msg['From'] = 'edm@choozmo.com'
|
|
|
+msg['To'] = 'jeweiliang@gmail.com'
|
|
|
+
|
|
|
+text = MIMEText("感謝您填寫問卷,敬送您五萬元裝修折價券。")
|
|
|
+msg.attach(text)
|
|
|
+image = MIMEImage(img_data, name=os.path.basename("c:/tmp/coupon.png"))
|
|
|
+msg.attach(image)
|
|
|
+
|
|
|
+try:
|
|
|
+ server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
|
|
|
+ server.ehlo()
|
|
|
+ server.login(gmail_user, gmail_password)
|
|
|
+ server.sendmail(sent_from, to, msg.as_string())
|
|
|
+ server.close()
|
|
|
+
|
|
|
+ print ('Email sent!')
|
|
|
+except:
|
|
|
+ traceback.print_exc()
|
|
|
+ print ('Something went wrong...')
|
|
|
+
|