我想創建一個簡單的python腳本發送電子郵件。我用這個下面的代碼:發送電子郵件與python
import subprocess
params = {'from': '[email protected]',
'to': '[email protected]',
'subject': 'Message subject'}
message = '''From: %(from)s
To: %(to)s
Subject: %(subject)s
Message body
''' % params
sendmail = subprocess.Popen(['/usr/share/sendmail', params['to']])
sendmail.communicate(message)
但我recive以下錯誤消息時,我嘗試運行它:
Traceback (most recent call last):
File "/home/me/test.py", line 15, in <module>
sendmail = subprocess.Popen(['/usr/share/sendmail', params['to']])
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
任何人都知道解決這個問題,或者一個更好的代碼?
謝謝!
而不是調用sendmail二進制文件,你可以使用內置的smtp庫http://docs.python.org/library/email-examples.html – Gryphius
我會試試看,謝謝! – fatninja
任何特殊原因**不能**使用python的smtplib或email模塊? – guidot