"至"在配置send_mail时,参数必须是列表或元组

时间:2016-06-27 07:41:41

标签: django

to argument is list right,所以这里有什么不对 我正在尝试发送到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 , 'otheremail@email.com']
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,
)

这意味着什么。我已经在settings.py文件中完成了设置,看起来像这样。

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'anything@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587

1 个答案:

答案 0 :(得分:1)

在send_mail部分中,您需要参考列表,而不是引用未定义的字符串...

将其更改为此应该有效:

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 , 'otheremail@email.com']
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,
)