views:

19

answers:

3

Hello, I want to send an email with a template like this.

{% extends "base.html" %}

{% block content %}
<h2>Invoice Details</h2>
<div id="horizontalnav">
  <a href="/index/add_invoice">Add an Invoice</a>
  <a href="/index/work_orders">Add a Work Order</a>
  <a href="/index/add_payment">Add Payment</a>
</div>
<ul STYLE="border: 1px solid;float:left;padding:15px; width: 700px;">
<img src="{{ MEDIA_URL }}images/c2duo.png" border="0" STYLE="text-alignment:left">
<h2 STYLE="text-align: right; COLOR:blue; Font-family:ARIAL">
INVOICE</h2>
<br/>
  <b>C2DUO</b>
     <br/>
  <i style="text-align:left">Simply adding value</i>
  <div id="list">
     {% for invoice in invoices_list %}
       <p style="text-align: right;">INVOICE # {{invoice.invoice_no}}<br/>
       {{invoice.date}}<br/>
       {{invoice.contract_info}}<br/>
       {% for invoice in invoice.work_orders.all %}
         {{invoice}}<br/>
       {% endfor %}
     {% endfor %}
   <p style="text-align: left">
   <p>To</p>
   {{client.company}}<br/>
   {{client.address}}<br/>
   {{client.city}}<br/>
   {{client.postcode}}<br/>
   <p>
    </div>
</ul>
{% endblock %}

I want to send fully html powered templates, with django datas. However I am having some problems. I am getting this error.

"to" argument must be a list or tuple

I am assuming there might be a problem with my views with the send to email domain, but there should not be a problem with this. I somehow am getting stuck with this.

#views.py
    @login_required
    def invoice_mail(request):
        t = loader.get_template('registration/email.txt')
        c = Context({
        'invoices_list': 'invoices_list',
        'clients_list': 'clients_list',
        })
        send_mail('Welcome to My Project', t.render(c), '[email protected]', '[[email protected]]', fail_silently=False)
+1  A: 

The error message is fairly explicit. The to argument to send_mail, which is the fourth positional argument, needs to be a list or tuple. You're passing a string, with brackets inside the string, for some reason.

send_mail('Welcome to My Project', t.render(c), '[email protected]', 
          ['[email protected]'], fail_silently=False)
Daniel Roseman
A: 
send_mail('Welcome to My Project', t.render(c), '[email protected]', '[[email protected]]', fail_silently=False)

has to be

send_mail('Welcome to My Project', t.render(c), '[email protected]', ['[email protected]'], fail_silently=False)
Ashok
A: 

'[[email protected]]' is not a list, it is a string with square brackets at each end. Try ['[email protected]'] instead.

Ignacio Vazquez-Abrams
Argh! so careless!
Shehzad009