メールを送信する単純な 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
この問題の解決策、またはより良いコードを知っている人はいますか?
ありがとう!