Sparkpost always throwing Response code 400 (Bad Request)


#1

I’ve followed all the steps and the Mail driver for sparkpost doesn’t seem to work.

.env

MAIL_CONNECTION=sparkpost
SPARKPOST_API_KEY=randomKey

and

const user = {
  name: 'Person',
  email: 'person@domain.com',
  password:  'somepassword',
  token_confirmation: randomString({ length: 40 })
}

// send confirmation email
await Mail.send('emails.account_confirmation', user, (message) => {
  message
    .from('hello@domain.com', 'Domain.com')
    .to(user.email, user.name)
    .subject('Account Confirmation')
})

The result is always:


#2

Hey friend,
According the documentation you should use this code

await Mail .connection('sparkpost') .send('view', data, (message) => { }) and the reason is because mail use smtp as default.

Another thing is that when you tried to send an email via SparkPost it actually use an sending domain sandbox. And to fix this you have to go at your SparkPost and set it up. Follow all the step and then try again.

If you want to check whether I right or not, just download the postman project and then run transmission route and you will get this message right here


#3

Thanks, it wasn’t the configuration as .env is already set to sparkpost. As you said I needed to use the domain setup with spark and I had a typo on the from "noreply@domain.com". It is now working.