protected function setParameters(Swift_Mime_SimpleMessage $message, $data)
    {
        $this->numberOfRecipients = 0;

        $smtp_api = [];
        foreach ($message->getChildren() as $attachment) {
            if (!$attachment instanceof Swift_Image
                || !in_array(self::SMTP_API_NAME, [$attachment->getFilename(), $attachment->getContentType()])
            ) {
                continue;
            }
            $smtp_api = self::decode($attachment->getBody());
        }

        if (!is_array($smtp_api)) {
            return $data;
        }

        foreach ($smtp_api as $key => $val) {

            switch ($key) {

                case 'api_key':
                    $this->apiKey = $val;
                    continue 2;

                case 'personalizations':
                    $this->setPersonalizations($data, $val);
                    continue 2;

                case 'attachments':
                    $val = array_merge($this->attachments, $val);
                    break;

                case 'unique_args':
                    throw new \Exception('Sendgrid v3 now uses custom_args instead of unique_args');

                case 'custom_args':
                    foreach ($val as $name => $value) {
                        if (!is_string($value)) {
                            throw new \Exception('Sendgrid v3 custom arguments have to be a string.');
                        }
                    }
                    break;

            }

            array_set($data, $key, $val);
        }
        return $data;
    }