msg.attach multiple attachments and passing vars to html

MRAB python at mrabarnett.plus.com
Wed Sep 1 02:44:10 CEST 2010


On 01/09/2010 00:24, aurfalien at gmail.com wrote:
> Hi,
>
> Few questions as I've been at this for dayz.
>
> Can I do multiple attachments in order via msg.attach as so;
>
> part1 = MIMEText(html, 'html')
> msg.attach(part1)
> part2 = MIMEText(text, 'plain')
> msg.attach(part2)
> part3 = MIMEText(html, 'html')
> msg.attach(part3)
>
> I desire to attach part1, part2 and part3 in that order.
>
This might help:

     http://snippets.dzone.com/posts/show/2038

> 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%", password)

That's the general idea.



More information about the Python-list mailing list