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]".
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.
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.
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.
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).
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
)
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