Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send multiple recipient sendgrid V3 api Python

Anyone please help, I am using sendgrid v3 api. But I cannot find any way to send an email to multiple recipients. Thank in advance.

    import sendgrid
    from sendgrid.helpers.mail import *

    sg = sendgrid.SendGridAPIClient(apikey="SG.xxxxxxxx")
    from_email = Email("FROM EMAIL ADDRESS")
    to_email = Email("TO EMAIL ADDRESS")
    subject = "Sending with SendGrid is Fun"
    content = Content("text/plain", "and easy to do anywhere, even with Python")
    mail = Mail(from_email, subject, to_email, content)
    response = sg.client.mail.send.post(request_body=mail.get())
    print(response.status_code)
    print(response.body)
    print(response.headers)

I want to send email to multiple recipient. Like to_mail = " [email protected], [email protected]".

like image 743
P113305A009D8M Avatar asked May 31 '18 00:05

P113305A009D8M


People also ask

How do I send an email to multiple recipients in SendGrid?

The most straightforward way to send bulk emails is to have an array of addresses in the to field, and then call sendMultiple with a single message object. Copy this code into index. js and replace the emails in the to array with your email addresses. const sgMail = require('@sendgrid/mail'); sgMail.

How many emails can be sent at once in SendGrid?

Are there limits on how often I can send email and how many recipients I can send to? There are rate limits on how frequently you can call the v3 Mail Send endpoint. Currently, you may make up to 10,000 requests per second to our endpoint. Each email you send may include up to 1000 recipients.

How do I send multiple emails in SMTP?

By default, a single SMTP transport creates a single connection and re-uses it for the lifetime of the script execution. You may send multiple e-mails through this SMTP connection. A RSET command is issued before each delivery to ensure the correct SMTP handshake is followed.

Can you CC in SendGrid?

SendGrid supports the capability to send the single email to one or more recipients in the TO field plus one or more recipients in the CC or BCC fields (reference here: https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html).


1 Answers

You can send an email to multiple recipients by listing them in the to_emails parameter of the Mail constructor:

from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import *

message = Mail(
    from_email='[email protected]',
    to_emails=[To('[email protected]'), To('[email protected]')],
    subject='Subject line',
    text_content='This is the message of your email',
)

sg = SendGridAPIClient(SENDGRID_API_KEY)
response = sg.send(message)

With this configuration, each recipient will be able to see each other listed on the email. To avoid this, use the is_multiple parameter to tell Sendgrid to create a new Personalization for each recipient:

message = Mail(
    from_email='[email protected]',
    to_emails=[To('[email protected]'), To('[email protected]')],
    subject='Subject line',
    text_content='This is the message of your email',
    is_multiple=True  # Avoid listing all recipients on the email
)
like image 180
Luke Taylor Avatar answered Sep 23 '22 08:09

Luke Taylor