我使用sendgrid的python模塊(https://github.com/sendgrid/sendgrid-python)發送交易電子郵件。我需要在預定時間發送電子郵件的語法方面的幫助。 一般sendgrid文檔要求修改json爲「{」send_at「:1409348513}」。我相信這個json不能在sendgrid-python中直接訪問。我需要語法來做與python庫等價的事情。使用sendgrid計劃電子郵件python
我現在的代碼相當於下面複製的代碼。如果有人能夠建議如何修改該代碼以在特定時間安排它,那將是非常好的,例如, datetime.dateime.now()+ datetime.timedelta(天= 1)
import sendgrid
from sendgrid.helpers.mail import Email, Content, Substitution, Mail
import urllib2 as urllib
def send_email_custom():
sg = sendgrid.SendGridAPIClient(apikey=myApiKey)
from_email = Email(sendEmail)
to_email = Email(custEmail)
reply_to_email = Email(receiveEmail)
content = Content("text/html", "Introduction")
mail = Mail(from_email, subject="Hi!", to_email=to_email, content=content)
mail.personalizations[0].add_substitution(Substitution("_firstName_", firstName))
mail.set_template_id(templateId)
try:
response = sg.client.mail.send.post(request_body=mail.get())
except urllib.HTTPError as e:
print(e.read())
return False
if response.status_code >=200 and response.status_code < 300:
return True
else:
return False
我會建議發佈此github回購,而不是SO – bwest