-
Notifications
You must be signed in to change notification settings - Fork 780
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
Email Client should be enhanced for instances specific to it's key #1282
Comments
Hi @aimythgit this should help. Let us know if you run into issues doing that. |
I saw this but didn't see a signature document for the send method. const sgClient1 = new Client(); // What should be this method. As it can't be send as in the client context this should be sendMail... or Besides the client is for all functionality of sendgrid, would prefer only for emailclient if possible. |
Hello @aimythgit, I believe you should use With best regards, Elmer |
Elmer, Either expose the mail client from this package that support instances @sendgrid/client |
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. |
While the default export of const { MailService } = require('@sendgrid/mail');
const service1 = new MailService();
service1.setApiKey('API_KEY1');
const service2 = new MailService();
service2.setApiKey('API_KEY2');
// alternatively you can also pass in the client (so you can reuse it for the other non-mail apis)
const { Client } = require('@sendgrid/client');
const client3 = new Client();
client3.setApiKey('API_KEY3');
const service3 = new MailService();
service3.setClient(client3);
await service3.send({...});
await client3.request({...}); // for non-mail related apis |
Issue Summary
The email client should allow instances of client as opposed to a singleton to facilitate multiple keys
Almost every SaaS provider client has instances and this client too should provide an option while the current simpler one can be used by those who do not have this use case. The whole purpose of a client is for the statefulness else the corresponding stateless REST API can be used directly without the clients.
Code Snippet
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
paste code here
const SgMailClient = require('@sendgrid/mailClient');
const client1 = new SgMailClient();
client1.setApiKey(process.env.SENDGRIDClient1_API_KEY);
const client2 = new SgMailClient();
client2.setApiKey(process.env.SENDGRIDClient2_API_KEY);
// logic for using client 1 or client 2 to send mail
The text was updated successfully, but these errors were encountered: