E-Mail Parsing

Merrigan charl.loubser at gmail.com
Thu Dec 13 07:39:04 EST 2007


On Dec 13, 9:29 am, Matt Nordhoff <mnordh... at mattnordhoff.com> wrote:
> Merrigan wrote:
> > I am writing a script to administer my E-Mail Server. The One thing
> > I'm currently struggling with is kind of Parsing the E-Mail adress
> > that I supply to the script.
>
> > I need to get the username (The part BEFORE the @ sign) out of the
> > address so that I can use it elsewhere. The problem I have with this
> > is that both the domain, and the username are variable lenghts and
> > that I have no idea how to split the two parts.
>
> > Is there any way that I can do this?
>
> > Thank ye very much.
> >>> addr = "u... at example.com"
> >>> addr.split("@")
>
> ['user', 'example.com']
>
> If it's formatted like a To header ("User <u... at example.com>"), use
> email.Utils.parseaddr() to get the address out of it.\
>
> The email modules might help you a lot:
>
> <http://docs.python.org/lib/module-email.html>
> --

Hi Matt,

Thank you very much for the help. It was exactly what I was looking
for, and made my script much safer and easier to use.

Blessings!

 -- Merrigan



More information about the Python-list mailing list