Question about InboundMailHandler.
class MailHandle(InboundMailHandler):
def receive(self, mail_message):
mail_message.sender may contained "John Bolton <john78@mail.com>". How can i extract "john78@mail.com" from it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve been using this regex, which works very well. It might theoretically be possible to engineer a sender which fails this regex, that’s why I catch the exception and alert about the address. It has not happened yet though.
The other answer is not compatible with the official email address format, as defined per RFC 2822.
Please note that this snippet mentions recipients, but if you read the spec, it applies to senders also.
https://www.rfc-editor.org/rfc/rfc2822#section-3.4