• R/O
  • SSH

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révisionabc366b09e0480fc4f594f41eab6c3766de065ab (tree)
l'heure2008-10-27 20:12:58
Auteuriselllo
Commiteriselllo

Message de Log

I added a python script which allows me to send emails using smtplib.

Change Summary

Modification

diff -r 176b8405c355 -r abc366b09e04 Python-codes/sendmail_smtplib.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Python-codes/sendmail_smtplib.py Mon Oct 27 11:12:58 2008 +0000
@@ -0,0 +1,41 @@
1+#!/usr/bin/python
2+
3+import smtplib
4+from email.MIMEMultipart import MIMEMultipart
5+from email.MIMEBase import MIMEBase
6+from email.MIMEText import MIMEText
7+from email import Encoders
8+import os
9+
10+gmail_user = "lorenzo.isella@gmail.com"
11+gmail_pwd = "mypasswd"
12+
13+def mail(to, subject, text, attach):
14+ msg = MIMEMultipart()
15+
16+ msg['From'] = gmail_user
17+ msg['To'] = to
18+ msg['Subject'] = subject
19+
20+ msg.attach(MIMEText(text))
21+
22+ part = MIMEBase('application', 'octet-stream')
23+ part.set_payload(open(attach, 'rb').read())
24+ Encoders.encode_base64(part)
25+ part.add_header('Content-Disposition',
26+ 'attachment; filename="%s"' % os.path.basename(attach))
27+ msg.attach(part)
28+
29+ mailServer = smtplib.SMTP("smtp.gmail.com", 587)
30+ mailServer.ehlo()
31+ mailServer.starttls()
32+ mailServer.ehlo()
33+ mailServer.login(gmail_user, gmail_pwd)
34+ mailServer.sendmail(gmail_user, to, msg.as_string())
35+ # Should be mailServer.quit(), but that crashes...
36+ mailServer.close()
37+
38+mail("isella@lorenzo.com",
39+ "Hello from python!",
40+ "This is a email sent with python",
41+ "temp.dat")