Since I'm about to use django-mailer in a project, I've looked to the
source code in order to try to use it. I currently only have only
plain text messages, but I will use HTML messages very soon and I
would like to know the approach that had been taken.
It seems that with the current design, I will create a Message
instance with nearly the entire mail source as the message body (the
text version, the html version and the additional headers).
Am I wrong ?
PS: Is it safe to start to use django-mailer today ?
Thanks in advance
--
Fabien SCHWOB
I haven't done anything with HTML messages yet, although that's
obviously something we'll need to support.
James
On Thu, 16 Aug 2007 16:42:47 +0200, "Fabien Schwob" <xphu...@gmail.com>
said:
--
James Tauber http://jtauber.com/
journeyman of some http://jtauber.com/blog/
> I haven't done anything with HTML messages yet, although that's
> obviously something we'll need to support.
I've founded how to support HTML in django-mailer. The solution is to
build the message with the Django provided classes
(EmailMultiAlternatives and EmailMessage).
>>> # Code from the Django docs
>>> from django.core.mail import EmailMultiAlternatives
>>>
>>> subject, from_email, to = 'hello', 'fr...@example.com', 't...@example.com'
>>> text_content = 'This is an important message.'
>>> html_content = '<p>This is an <strong>important</strong> message.</p>'
>>> msg = EmailMultiAlternatives(subject, text_content, from_email, to)
>>> msg.attach_alternative(html_content, "text/html")
At this point, you have an EmailMultiAlternatives instance. You can
get a django.core.mail.SafeMIMEText object (a subclass of Python's
email.MIMEText.MIMEText class) or a django.core.mail.SafeMIMEMultipart
by calling message(). And since the Python message object has a
as_string() methods, you can get the message that you would store in
django-mailer
And this point, you loop through the message and send them with
smtplib (which take the full message as parameter).
Is it a good solution ?
--
Fabien SCHWOB