Mailgun:'to'参数不是有效地址

时间:2017-05-26 16:31:32

标签: python mailgun

我正在使用for循环来安排使用Mailgun发送一些电子邮件。第一封电子邮件获得200响应并正确发送。但其余3封电子邮件都收到400响应,并出现以下错误'to' parameter is not a valid address. please check documentation"。我完全难过了。我已经挑出了所有的东西,而且看起来都是正确的。任何帮助将不胜感激。

def indoctrination(email, name):
    requests.post('https://api.mailgun.net/v3/lists/{}@{}/members'.format(list, domain_url),
            auth=auth,
            data={'subscribed': True,
                  'address': email,
                  'name': name})
    for x in range(1,5):
        if x > 1:
            days = x - 1
            time = datetime.utcnow() #+ timedelta(days=days)
        else:
            time = datetime.utcnow()
        subject = ['Welcome to Python Financial', 'Notes and Pizza', 'Your questions answered', 'Why are we not doing this?']
        email = requests.post('https://api.mailgun.net/v3/{}/messages'.format(domain_url),
                auth=auth,
                data={"from": from_email,
                      "to": '{} <{}>'.format(name, email),
                      "subject": "{}".format(subject[x-1]),
                      "html": open("templates/email{}.html".format(x)),
                      "o:deliverytime": time.strftime("%a, %d %b %Y %H:%M:%S +0000")})
        print 'Response status code: ', email.status_code
        print 'Data: ', email.json()

2 个答案:

答案 0 :(得分:0)

如果您是由于Laravel中的相同错误而来这里的,请检查您是否在Mailable中使用Notification类。在这种情况下,Laravel不会自动从email替换$notifiable,您会收到此错误。您需要指定to参数或使用MailMessage,在这种情况下效果很好。

答案 1 :(得分:-2)

见评论。刚刚重命名了电子邮件变量以进行修复。