を使っsmtplib
て簡単にメールを送ることができます。私が苦労しているのは、送信された実際のヘッダーを読み取ることです。具体的には、私は読むことを探していますMessage-ID
とReferences
。
私は最初はそれsendmail()
が彼らを返すだろうと思ったが、そうではない。
smtpilb.stderr
自分の関数にリダイレクトして、必要なデータを解析できることがわかりました。私が言うことを可能にするより良い方法はありますか?
headers['References']
If you use sendmail()
I am not sure how to access the headers, because you don't have a Message
object in that case. However, if you use send_message
instead - which is very similar to sendmail()
- and pass it an email.message.Message
object, then all of the email message headers and their values are stored in a dict in your Message
object. So e.g., Message-ID can be accessed from an email message object msg
with msg['Message-ID']
, subject can be accessed using msg['Subject']
, etc. I don't think anything will be stored in message-id
unless you put it there yourself though. You can 'roll your own' Message-ID using make_msgid()
from email.utils
:
from email.utils import make_msgid
msg['Message-ID'] = make_msgid()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加