Discussion:
[Tutor] Variables in email addresses
Oliver Mercer-Deadman
2015-06-17 01:05:49 UTC
Permalink
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 = '***@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
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Laura Creighton
2015-06-17 11:04:39 UTC
Permalink
Post by Oliver Mercer-Deadman
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
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

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Joel Goldstick
2015-06-17 12:42:53 UTC
Permalink
Post by Laura Creighton
Post by Oliver Mercer-Deadman
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
I realise that it is probably not correct, I am only in the foothills, but
in principal can it be done?
If the user input value is just the name, then you need to concatinate
Post by Laura Creighton
Post by Oliver Mercer-Deadman
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.
http://pymotw.com/2/smtplib/
But be warned, this uses Python 2 syntax, not Python 3.
Laura
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
--
Joel Goldstick
http://joelgoldstick.com
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Continue reading on narkive:
Loading...