giaggi
giaggi

Reputation: 572

sendgrid - How to get the email id of a just sent email

I am using python and sendgrid to send emails from my application.

I successfully integrated with Sendgrid and I am able to send emails BUT I am not understanding where can I find the message_id of an email I just sent.

I need such id so I can store it on my end and later on re-use it retrieve informations about the email from sendgrid.

I checked the response but there is no trace of the message id.

This is the code I am using

#define to emails
to_emails = [(outreach.contact.email, outreach.contact.name_surname)]
#define cc emails
cc_emails = [(outreach.contact.owner.email, outreach.contact.owner.first_name + ' ' + outreach.contact.owner.last_name),]
##Adding PM e PC in cc to all emails
CCs = outreach.position.jobproject.crew.filter(
                        Q(position_status=POSITION_STATUS[3][0]) &
                        (Q(title__title_name='Production Coordinator') |
                         Q(title__title_name='Production Manager') |
                         Q(title__title_name='Producer')
                         )
                    )

print(CCs)
for cc in CCs:
    cc_emails.append((cc.booked.email,cc.booked.name_surname))

#define bcc emails
#bcc_emails = [('[email protected]', outreach.contact.owner.first_name + ' ' + outreach.contact.owner.last_name)]

#define message object
message = Mail(
    from_email = (SENDER, outreach.contact.owner.first_name + ' ' + outreach.contact.owner.last_name),
    to_emails = to_emails,
    subject = outreach.emails.filter(action = email_action)[0].subject,
    html_content = outreach.emails.filter(action = email_action)[0].body
)


#add cc to message
for cc in cc_emails:
    if cc[0] != to_emails[0][0]:
        message.add_cc(cc[0])

#add bcc to message
#for bcc in bcc_emails:
#    message.add_bcc(bcc[0])

#add reply to to message
message.reply_to = (
    outreach.contact.owner.email,
    outreach.contact.owner.first_name + ' ' + outreach.contact.owner.last_name
)



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

    

Upvotes: 0

Views: 2021

Answers (1)

Related Questions