Sendgrid is a popular service to send out marketing or transactional email. The Sendgrid - Vaultastic connector can be used to archive a copy of every mail sent.
Though Sendgrid has deprecated the BCC functionality from the GUI, if you use the SendGrid API to send out emails from your applications, you can send a copy of all or selected mail to Vaultastic.
The section below take you through the steps and also has a sample Python code which is used to send a mail to any recipient with a bcc copy.
Step 1: Generate the API Key
1. Login to your sendgrid account at https://sendgrid.com/
2. Navigate to the Settings
3. Select API Keys and click on the Create API Key button
4. Give a suitable name and select Full Access in the Permissions section. Click the Create & View button
5. The key will be generated. The key will be displayed on the console only once. Copy the key to a notepad and save in a secure location. Click Done. This key will be required in the function used to send out email.
Step 2: Update the send mail function to send a bcc to the Vaultastic domain
- Update your send mail functions to send a blind carbon copy (bcc) of each mail to the journal id of your Vaultastic domain. The bcc id should be an id on your Vaultastic domain.. For example if your vaultastic domain is acmecorp-com.vaultastic.com, the bcc id can be email@example.com
Reference: Sendgrid documentation recommends identifying bcc as a personalization in each API call.
- Use the sample python code below to update your code. The code takes the API Key, From, To, Bcc, Subject, and Content as parameters to send mail using the SendGrid API.
from sendgrid import SendGridAPIClient from sendgrid.helpers.mail import * def validate_input(api_key): try: sendgrid_client = SendGridAPIClient(api_key) response = sendgrid_client.client.api_keys.get() return True, sendgrid_client except Exception as e: return False, str(e) def send_mail(sendgrid_client): from_email_value = str(input("Enter From: ")) to_email_value = str(input("Enter To: ")) bcc_email_value = str(input("Enter Bcc: ")) subject_email_value = str(input("Enter Subject: ")) content_email_value = str(input("Enter Content: ")) message = Mail() message.to = [ To( email = to_email_value ) ] message.bcc = [ Bcc( email = bcc_email_value ) ] message.from_email = From(email = from_email_value) message.subject = Subject(subject_email_value) message.content = [ Content( mime_type = "text/html", content = content_email_value ) ] try: response = sendgrid_client.send(message) except Exception as e: return False, str(e) if response.status_code == 202: return True, response.status_code return False, response.status_code if __name__ == '__main__': api_key = str(input("Enter API Key: ")) bool_type, value = validate_input(api_key) if not bool_type: print(value) exit(1) bool_type, value = send_mail(value) if not bool_type: print("Status Code: " + str(value)) exit(1) print("Status Code: " + str(value))