I'm trying to use sendgrid to send email from my Python application.
It's sending fine using the mail helper and the following syntax:
sgmessage = mail.Mail(from_email, message.subject, to_email, content)
sg.client.mail.send.post(request_body=sgmessage.get())
But I can't find the way to send an email which has a multipart/alternative content type with text & html versions?
I've tried things like this:
sgmessage = mail.Mail(from_email, message.subject, to_email)
sgmessage.add_content(content)
sgmessage.add_content(htmlcontent)
But that gives me Bad Request when I try to send.
Could someone point me to the documentation or other tip for achieving this?
Also attachments -- I can't find docs for that handy mail helper which would help me add attachments ability to my code.
Mail Helper Source https://github.com/sendgrid/sendgrid-python/blob/master/sendgrid/helpers/mail/mail.py
mail_html = Content(type_='text/html', value='<h1>Test Mail</h1><p>This is a test email message.</p>')
mail_txt = Content(type_='text/plain', value='This is a test email message.')
mail = Mail(mail_from, mail_subject, mail_to, mail_html)
mail.add_content(mail_txt)
response = sg.client.mail.send.post(request_body=mail.get())
The sample links are still 404's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With