django send_email [Errno 99] Cannot assign requested address

错误示范:

from django.core.mail import send_mail


send_mail(subject="subject",
          message="message",
          from_email='EMAIL_HOST_USER',                 
          recipient_list=['EMAIL_RECIPIENT'])

报错:

[Errno 99] Cannot assign requested address

问题原因:

看send_email源码:


def send_mail(subject, message, from_email, recipient_list,
              fail_silently=False, auth_user=None, auth_password=None,
              connection=None, html_message=None):
    """
    Easy wrapper for sending a single message to a recipient list. All members
    of the recipient list will see the other recipients in the 'To' field.

    If auth_user is None, use the EMAIL_HOST_USER setting.
    If auth_password is None, use the EMAIL_HOST_PASSWORD setting.

    Note: The API for this method is frozen. New code wanting to extend the
    functionality should use the EmailMessage class directly.
    """
    connection = connection or get_connection(
        username=auth_user,
        password=auth_password,
        fail_silently=fail_silently,
    )
    mail = EmailMultiAlternatives(subject, message, from_email, recipient_list, connection=connection)
    if html_message:
        mail.attach_alternative(html_message, 'text/html')

    return mail.send()

注意注释:

 If auth_user is None, use the EMAIL_HOST_USER setting.
 If auth_password is None, use the EMAIL_HOST_PASSWORD setting.

如果settings.py没有配置EMAIL_HOST_USER和 EMAIL_HOST_PASSWORD,需要手动传入auth_user和auth_password.

from django.core.mail import send_mail


send_mail(subject="subject",
          message="message",
          from_email='EMAIL_HOST_USER',                 
          recipient_list=['EMAIL_RECIPIENT'],
          auth_user='zhangsan',
          auth_password='ew33ddds')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值