Mailgun:'to' 参数不是有效地址
Mailgun: 'to' parameter is not a valid address
我正在使用 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()
见评论。刚刚重命名了电子邮件变量以修复。
如果您在 Laravel
中遇到同样的错误,请检查您是否在 Notification
中使用 Mailable
class。在这种情况下,Laravel
不会自动将 $notifiable
替换为 email
,您将收到此错误。您需要指定 to
参数或使用 MailMessage
,这在这种情况下会很好用。
我正在使用 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()
见评论。刚刚重命名了电子邮件变量以修复。
如果您在 Laravel
中遇到同样的错误,请检查您是否在 Notification
中使用 Mailable
class。在这种情况下,Laravel
不会自动将 $notifiable
替换为 email
,您将收到此错误。您需要指定 to
参数或使用 MailMessage
,这在这种情况下会很好用。