E-Mail Parsing

M

Merrigan

Hi There,

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.

-- Merrigan
 
M

Matt Nordhoff

Merrigan said:
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.
['user', 'example.com']

If it's formatted like a To header ("User <[email protected]>"), 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>
--
 
M

Merrigan

Merrigan said:
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.

['user', 'example.com']

If it's formatted like a To header ("User <[email protected]>"), 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
 
M

Matt Nordhoff

Merrigan said:
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

You're welcome. :)
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top