我正在尝试创建一个发送电子邮件的简单 python 脚本。我使用了以下代码:
import subprocess
params = {'from': 'from@example.com',
'to': 'to@example.com',
'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)
但是当我尝试运行它时,我收到以下错误消息:
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
任何人都知道这个问题的解决方案,或者更好的代码?
谢谢!