import loggingfrom sendgrid import SendGridAPIClientfrom sendgrid.helpers.mail import Mail, Emailfrom python_http_client.exceptions import HTTPErrorlog = logging.getLogger(__name__)SENDGRID_API_KEY = 'SG.xx-mm...'message = Mail( to_emails="[email protected]", from_email=Email('[email protected]', "Desmond Lua"), subject=f"Welcome", html_content="<p>Hello World!</p>" )message.add_bcc("[email protected]")try: # https://github.com/sendgrid/sendgrid-python/blob/master/TROUBLESHOOTING.md#error # request_body = message.get() # response = sg.client.mail.send.post(request_body=request_body) response = sg.send(message) log.info(f"email.status_code={response.status_code}")except HTTPError as e: log.error(e)
❤️ Is this article helpful?
Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.
Do send some 💖 to @d_luaz or share this article.
✨ By Desmond Lua
A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz
👶 Apps I built
Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.