Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3434346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:41:15+00:00 2026-05-18T07:41:15+00:00

I am practicing sending emails with Google App Engine with Python. This code checks

  • 0

I am practicing sending emails with Google App Engine with Python. This code checks to see if message.sender is in the database:

class ReceiveEmail(InboundMailHandler):
    def receive(self, message):
        querySender = User.all()
        querySender.filter("userEmail =", message.sender)
        senderInDatabase = None
        for match in querySender:
            senderInDatabase = match.userEmail

This works in the development server because I send the email as "az@example.com" and message.sender="az@example.com"

But I realized that in the production server emails come formatted as "az <az@example.com> and my code fails because now message.sender="az <az@example.com>" but the email in the database is simple "az@example.com".

I searched for how to do this with regex and it is possible but I was wondering if I can do this with Python lists? Or, what do you think is the best way to achieve this result? I need to take just the email address from the message.sender.

App Engine documentation acknowledges the formatting but I could not find a specific way to select the email address only.

Thanks!

EDIT2 (re: Forest answer)

@Forest:
parseaddr() appears to be simple enough:

>>> e = "az <az@example.com>"
>>> parsed = parseaddr(e)
>>> parsed
('az', 'az@example.com')
>>> parsed[1]
'az@example.com'
>>>

But this still does not cover the other type of formatting that you mention: user@example.com (Full Name)

>>> e2 = "<az@example.com> az"
>>> parsed2 = parseaddr(e2)
>>> parsed2
('', 'az@example.com')
>>>

Is there really a formatting where full name comes after the email?

EDIT (re: Adam Bernier answer)

My try about how the regex works (probably not correct):

r    # raw string
<     # first limit character
(     # what is inside () is matched     
[       # indicates a set of characters
^         # start of string
>         # start with this and go backward?
]       # end set of characters
+       # repeat the match
)     # end group
>    # end limit character
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:41:15+00:00Added an answer on May 18, 2026 at 7:41 am

    If you want to use regex try something like this:

    >>> import re
    >>> email_string = "az <az@example.com>"
    >>> re.findall(r'<([^>]+)>', email_string)
    ['az@example.com']
    

    Note that the above regex handles multiple addresses…

    >>> email_string2 = "az <az@example.com>, bz <bz@example.com>"
    >>> re.findall(r'<([^>]+)>', email_string2)
    ['az@example.com', 'bz@example.com']
    

    but this simpler regex doesn’t:

    >>> re.findall(r'<(.*)>', email_string2)
    ['az@example.com>, bz <bz@example.com'] # matches too much
    

    Using slices—which I think you meant to say instead of “lists“—seems more convoluted, e.g.:

    >>> email_string[email_string.find('<')+1:-1]
    'az@example.com'
    

    and if multiple:

    >>> email_strings = email_string2.split(',')
    >>> for s in email_strings:
    ...   s[s.find('<')+1:-1]
    ...
    'az@example.com'
    'bz@example.com'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm practicing drawing polyline on the Map. I've adopted Sample code from download here.
I'm practicing for the upcoming ACM programming competition in a week and I've gotten
While practicing the jxl API, i cant extract details from certain Excel sheet its
While practicing different scenarios in which CSS3 pseudo-classes and selectors might come in handy,
I am practicing using pointers. I have a pointer to an array of 3
I am practicing for an exam, and found a sample problem that gets me
I'm practicing with Ruby and regex to delete certain unwanted characters. For example: input
I am practicing over the summer to try and get better and I am
I have been practicing TDD and (some) XP for a few years now and
I was practicing writing macros and I can't seem to get defn to work.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.