patrick
patrick

Reputation: 1

"to" argument must be a list or tuple while configuring send_mail

to argument is list right, so whats wrong in here I am trying to send to more than one address in to_email

from django.core.mail import send_mail
from django.conf import settings


subject = 'Where is the fault'
from_email = settings.EMAIL_HOST_USER
to_email = [from_email , '[email protected]']
contact_message = "%s: %s via %s" % (
    form_full_name , 
    form_message , 
    form_email)

send_mail(
    'subject',
    'contact_message.',
    'from_email',
    'to_email',
    fail_silently=False,
)

What does this means. I have already done settings in my settings.py file which looks like this.

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

Upvotes: 0

Views: 4487

Answers (1)

Tim
Tim

Reputation: 1591

In your send_mail section, you need to refer to the list, instead you're referring to strings, that aren't defined...

Change it to this and it should work:

from django.core.mail import send_mail
from django.conf import settings


subject = 'Where is the fault'
from_email = settings.EMAIL_HOST_USER
to_email = [from_email , '[email protected]']
contact_message = "%s: %s via %s" % (
    form_full_name , 
    form_message , 
    form_email)

send_mail(
    subject,
    contact_message.,
    from_email,
    to_email,
    fail_silently=False,
)

Upvotes: 1

Related Questions