2017-05-26 18 views
0

我正在使用for循環來計劃使用Mailgun發送一些電子郵件。第一封電子郵件得到200響應並正確發送。但其餘3封電子郵件都收到400迴應,並且出現以下錯誤'to' parameter is not a valid address. please check documentation"。我完全被難住了。我已經單獨列出了一切,看起來都是正確的。任何幫助將不勝感激。Mailgun:'to'參數不是有效地址

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() 
+0

我犯了多麼愚蠢的錯誤。當我將'email'傳遞給函數時,我更改了變量以創建消息,所以我沒有在'to:'字段中輸入有效的電子郵件地址。通過重命名函數中的電子郵件變量可以簡單地解決問題。 – freefly0313

+0

這個問題值得保留嗎?你犯了一個錯字。我不認爲有人會從中學到任何東西。 – toxaq

回答

0

查看評論。只需重新命名電子郵件變量即可修復。