SendGrid send email via IP Pool

Twilio SendGrid SMTP service can send emails via IP Pool, JSON string with SMTP objects. This is possible by including a header named X-SMTPAPI.


https://docs.sendgrid.com/for-developers/sending-email/building-an-x-smtpapi-header#ip-pools 

https://docs.sendgrid.com/for-developers/sending-email/quickstart-python  


The information about verifying and setting up an IP pool and associated domain with IPs.


https://app.sendgrid.com/settings/sender_auth/ 

 

https://app.sendgrid.com/settings/ip_addresses 


https://app.sendgrid.com/settings/sender_auth/reverse_dns/

When your setting is ready, i can create script to test email sending via right IP Pool.


Email example raw json without helper.

https://github.com/sendgrid/sendgrid-python/blob/main/examples/mail/mail.py

Code for Mail object

https://github.com/sendgrid/sendgrid-python/blob/main/sendgrid/helpers/mail/mail.py

Don't be mistaken with 

https://github.com/sendgrid/sendgrid-python/blob/main/sendgrid/helpers/mail/email.py

My own test script example

def create_message(self, item):
        current_site = Site.objects.get_current()
        from_email = Email(self.from_email)
        to_email = To(item.email)
        html = render_to_string('spontaneousmail/profilemail.html',
                                    { 'site': current_site, 'cyclus':item})
        content = Content("text/html", html)
        subject = item.job.title 

        email = Mail(from_email, to_email, subject, content)
        email.ip_pool_name = IpPoolName("POOLNAME_AS_IN_ADMIN")
        return email



Comments