Python のemail
モジュールは、ヘッダーの解析に最適です。ただし、To:
ヘッダーには複数の受信者を含めることができ、複数のTo:
ヘッダーが存在する場合があります。では、各メール アドレスを分割するにはどうすればよいでしょうか。コンマは引用できるので、コンマで区切ることはできません。これを行う方法はありますか?
デモコード:
msg="""To: user1@company1.com, "User Two" <user2@company2.com", "Three, User <user3@company3.com>
From: anotheruser@user.com
Subject: This is a subject
This is the message.
"""
import email
msg822 = email.message_from_string(msg)
for to in msg822.get_all("To"):
print("To:",to)
現在の出力:
$ python x.py
To: user1@company1.com, "User Two" <user2@company2.com", "Three, User <user3@company3.com>
$