javascript - How to use sparkpost without a CC and/or BCC recepient? -


here's transmission object:

  if(req.body.bcc === ''){      req.body.bcc = '';    }     if (req.body.cc === '') {      req.body.cc = '';    }     if (req.body.subject === '') {      req.body.subject = 'no subject';    }    if (req.body.source === '') {      req.body.source = '<email omitted>';    }    if (req.body.messagebody === '') {      req.body.messagebody = 'no body text has been entered';    }    var transmission = {      recipients: [        {          address: {            email: req.body.to,            name: 'to recipient'          },          substitution_data: {            recipient_type: 'original'          }        }      ],      cc: [        {          address: {            email: req.body.cc,          },          substitution_data: {            recipient_type: 'cc'          }        }      ],      bcc: [        {          address: {            email: req.body.bcc,          },          substitution_data: {            recipient_type: 'bcc'          }        }      ],      content: {        from: {          name: req.body.source,          email: req.body.source        },        subject: req.body.subject,        text: req.body.messagebody,        html: `<p></p>`      }    };

i have html input forms send entered data req.body, if there's no req.body.cc or req.body.bcc content, happens sparkpost throws error saying unaccessible entity and:

  name: 'sparkposterror',    errors:     [ { message: 'invalid header',         description: 'error while validating header cc: missing header content',         code: '3002' } ],    statuscode: 422 }

if put random number 1 in cc , bcc fields, message sends "to" user sparkpost tells me message failed send 2 recepients. feel i'm missing here because if there no bcc or cc recipients should send email in "to" field , shouldn't have enter random gibberish in cc or bcc send email. has ran issue or have idea how solve problem?

maybe can check if field blank, replace default value sparkpost know i'm not trying send email there, placeholder. if there such thing, haven't found yet.

here example of sending email without cc or bcc. if not have bcc or cc recipients don't include array objects.

{     "options": {         "open_tracking": true,         "click_tracking": true     },   "campaign_id": "test",   "recipients": [     {       "address": {         "email": "to@example.com",         "name": "to recipient"       },          "tags": [],         "substitution_data": {"recipient_type": "original"}      }   ],   "content": {     "from": {       "email": "from@example.com",       "name": "from address"     },     "subject": "my sample subject",     "text": "{{recipient_type}}",     "reply_to": "test@example.com",      "html": "<p>{{recipient_type}}</p>"   } } 

here example curl command:

curl -x post \   https://api.sparkpost.com/api/v1/transmissions \   -h 'authorization: your_api_key_here' \   -h 'cache-control: no-cache' \   -d '{     "options": {         "open_tracking": true,         "click_tracking": true     },   "campaign_id": "test",   "recipients": [     {       "address": {         "email": "to@example.com",         "name": "to recipient"       },          "tags": [],         "substitution_data": {"recipient_type": "original"}      }   ],   "content": {     "from": {       "email": "from@example.com",       "name": "from address"     },     "subject": "my sample subject",     "text": "{{recipient_type}}",     "reply_to": "test@example.com",      "html": "<p>{{recipient_type}}</p>"   } }  ' 

you need put api key , replace to/from addresses ones appropriate test case.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -