[Tutor] Variables in email addresses
Laura Creighton
lac at openend.se
Wed Jun 17 13:04:39 CEST 2015
In a message of Wed, 17 Jun 2015 02:05:49 +0100, Oliver Mercer-Deadman writes:
>Hi I am a complete newbie but am hoping to learn some python for a
>particular project. Before I hurl myself in I would like to know if a key
>element is going to be possible.
>
>I will need to be able to use a variable as the username in an email
>address. E.G.
>
>username = Input("Enter Something: ")
>
>Then later when sending email with SMTP
>to_addr = 'username at mycompany.com'
>
>I realise that it is probably not correct, I am only in the foothills, but
>in principal can it be done?
>
>Thanks,
>Ozzy
You can do this. Works great. Note, you will want to be using the
smtplib that is part of the Python standard library and not write
all of the code for talking to SMTP yourself. Somebody else has
already done this for you.
Interesting tutorial here:
http://pymotw.com/2/smtplib/
But be warned, this uses Python 2 syntax, not Python 3.
Laura
More information about the Tutor
mailing list