msg.attach multiple attachments and passing vars to html
clp2 at rebertia.com
Wed Sep 1 02:53:48 CEST 2010
On Tue, Aug 31, 2010 at 5:44 PM, MRAB <python at mrabarnett.plus.com> wrote:
> On 01/09/2010 00:24, aurfalien at gmail.com wrote:
>> Also, is it somehow possible to pas python vars to html?
>> My goal to to have an email that says something like;
>> Welcome to ACME.
>> A few LINKS to get you started.
>> Your user name is USRNM and your password is PASS
>> Where USRNM and PASS are python vars but the rest is an html based email.
>> LINKS is an actual hyperlink, hence the desire to do html based emails.
> Create a template HTML with placeholders and then the individual HTML
> by replacing the placeholders with the values, something like:
> template_html = "Your user name is %USRNM% and your password is %PASS%."
> user_html = template_html.replace("%USRNM%", username).replace("%PASS%",
> That's the general idea.
In the general case though, one needs to be sure to properly escape
the inserted text:
from cgi import escape
user_html = template_html.replace("%USRNM%",
Also, string formatting would probably be safer than .replace() in the
unlikely but not impossible event that user input and the magic
placeholder names overlap.
More information about the Python-list