Sha*_*rad 5 python email python-2.7 sendgrid
我正在使用 sendgrid 的 python 模块(https://github.com/sendgrid/sendgrid-python ) 的 python 模块来发送事务电子邮件。我需要有关在计划时间发送电子邮件的语法方面的帮助。\n一般 sendgrid 文档要求将 json 修改为“{ \xe2\x80\x9csend_at\xe2\x80\x9d: 1409348513 }”。我相信这个 json 不能在 sendgrid-python 中直接访问。我需要使用 python 库执行等效操作的语法。
\n\n我当前的代码相当于下面复制的代码。如果有人可以建议如何修改此代码以将其安排在特定时间,例如 datetime.dateime.now() + datetime.timedelta(days=1) ,那就太好了
\n\nimport sendgrid \nfrom sendgrid.helpers.mail import Email, Content, Substitution, Mail\nimport urllib2 as urllib\n\ndef send_email_custom(): \n sg = sendgrid.SendGridAPIClient(apikey=myApiKey) \n from_email = Email(sendEmail)\n to_email = Email(custEmail)\n reply_to_email = Email(receiveEmail)\n content = Content("text/html", "Introduction")\n mail = Mail(from_email, subject="Hi!", to_email=to_email, content=content)\n mail.personalizations[0].add_substitution(Substitution("_firstName_", firstName))\n mail.set_template_id(templateId)\n try:\n response = sg.client.mail.send.post(request_body=mail.get())\n except urllib.HTTPError as e:\n print(e.read())\n return False\n if response.status_code >=200 and response.status_code < 300:\n return True\n else:\n return False\nRun Code Online (Sandbox Code Playgroud)\n