Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail CustomArg is created on personalization instead of on the Mail itself. #1019

Open
patrickkusebauch opened this issue Nov 16, 2020 · 3 comments
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@patrickkusebauch
Copy link

patrickkusebauch commented Nov 16, 2020

Issue Summary

From SendGrid API documentation you can attach customArg on the mail object itself. However, this library will create a new personalization. This breaks any app that relies on personalization to send different variations of e-mails. It will either:

  1. Break - because this shadow personalization does not have data necessary that are included in every other personalization (like adding recipients in personalizations).
  2. Not apply customArg to the other personalizations - based on the API, customArg added on the mail object should be applied to ALL persionalization, unless overwritten in the personalization itself. Currently, the customArg is not applied to any.

Steps to Reproduce

  1. Create e-mail with all required fields except to
  2. Add 'customArg' to this email (call Mail::addCustomArg)
  3. Add personalizations that contain the to field

Expected behavior

E-mail can be successfully sent via API (status code 200/202 - whether sending for real or only for validation).

Current behavior

E-mail cannot be sent via API (status code 400). Body:

{"errors":[
  {
    "message":"The to array is required for all personalization objects, and must have at least one email object with a valid email address.",
    "field":"personalizations.0.to",
    "help":"http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.personalizations.to"
  }
]}

Technical details:

  • sendgrid-php version: master
  • php version: any
@thinkingserious
Copy link
Contributor

thinkingserious commented Nov 16, 2020

Hello @patrickkusebauch,

I think you may be able to achieve your use case by either passing in the personalization or the personalizationIndex. If not, could you please provide sample code that demonstrates what you are trying to achieve?

Thank you!

With best regards,

Elmer

@thinkingserious thinkingserious added status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Nov 16, 2020
@patrickkusebauch
Copy link
Author

patrickkusebauch commented Nov 17, 2020

Sure thing. This does not work:

        $api = new SendGrid('qwerty123456');
        $email = new Mail();
        $email->setFrom('[email protected]');
        $email->addContent(new Content("text/plain", 'bla'));
        $email->addContent(new Content("text/html", 'bla'));
        $email->addCustomArg('domain', 'localhost.net');
        for ($i = 1; $i<10; $i++) {
            $personalization = new Personalization();
            $personalization->addTo(new To('test' . $i . '@localhost.net'));
            $personalization->addCustomArg(new CustomArg('email_id', $i));
            $email->addPersonalization($personalization);
        }
        $api->send($email);

Notice the domain cusutomArg that breaks it. You can circumvent it by:

        $api = new SendGrid('qwerty123456');
        $email = new Mail();
        $email->setFrom('[email protected]');
        $email->addContent(new Content("text/plain", 'bla'));
        $email->addContent(new Content("text/html", 'bla'));
        for ($i = 1; $i<10; $i++) {
            $personalization = new Personalization();
            $personalization->addTo(new To('test' . $i . '@localhost.net'));
            $personalization->addCustomArg(new CustomArg('email_id', $i));
            $personalization->addCustomArg(new CustomArg('domain', 'localhost.net'));
            $email->addPersonalization($personalization);
        }
        $api->send($email);

But then you have the domain customArg on the Personalization itself and not on the e-mail. Which should be possible given the official docs I linked.

@thinkingserious
Copy link
Contributor

Ah, that makes sense. Thank you for taking the time to clarify for me.

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: bug bug in the library and removed status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

2 participants