Skip to content

Instantly share code, notes, and snippets.

@trouttdev
Last active November 16, 2016 08:20
Show Gist options
  • Save trouttdev/5eafb0d7b36d49ad2e4e to your computer and use it in GitHub Desktop.
Save trouttdev/5eafb0d7b36d49ad2e4e to your computer and use it in GitHub Desktop.
How to add CC and BCC fields to SparkPost API

How to send a SparkPost email via API with a CC and BCC

Originally I found this which only vaguely pointed me in the right direction, so I thought I'd create a gist of what ended up working for me.

CC

To add a CC address, you have to two two things

  1. Add the address to your recipeints array, and set the header_to value to an address in the to field. So if you're sending the email to [email protected] and CCing it to [email protected], the header_to for [email protected] will need to be set to [email protected]
  2. Add the email to the CC headers option in content object. If you have multiple emails, these should be comma separated.

BCC

BCC Seems to be simpler than CC since it's only one step, you just need to repeat step #1 from CC and you're good to go.

  1. Add the address to your recipeints array, and set the header_to value to an address in the to field. So if you're sending the email to [email protected] and BCCing it to [email protected], the header_to for [email protected] will need to be set to [email protected]

Exmaple

Below is an example which worked for me:

{
	"content": {
		"subject": "Test Message",
		"html": "This is a test message.",
		"headers": {
			"CC": "[email protected],[email protected]" // add all CC addresses here, comma separated
		},
		"from": {
			"email": "[email protected]",
			"name": "Test Sender"
		}
	},
	"recipients": [{
    		"address": {
    			"email": "[email protected]",
    			"header_to": "[email protected]"
    		}
    	}, {
    		"address": {
    			"email": "[email protected]",
    			"header_to": "[email protected]" // note this address is the same as an address in the "to" field
    		}
       }, {
           "address": {
               "email": "[email protected]",
               "header_to": "[email protected]" // note this address is the same as an address in the "to" field
           }
      }, {
          "address": {
              "email": "[email protected]",
              "header_to": "[email protected]" // note this address is the same as an address in the "to" field
          }
     }
    ],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment