我使用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