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

Email Client should be enhanced for instances specific to it's key #1282

Open
aimythgit opened this issue Jul 4, 2021 · 6 comments
Open
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@aimythgit
Copy link

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

@shwetha-manvinkurke
Copy link
Contributor

Hi @aimythgit this should help. Let us know if you run into issues doing that.

@shwetha-manvinkurke shwetha-manvinkurke added status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Jul 12, 2021
@aimythgit
Copy link
Author

aimythgit commented Jul 20, 2021

I saw this but didn't see a signature document for the send method.

const sgClient1 = new Client();
const sgClient2 = new Client();
sgClient1.setApiKey('KEY1');
sgClient2.setApiKey('KEY2');

// What should be this method. As it can't be send as in the client context this should be sendMail...
sgClient1.send(msg)

or
const mailClient1 = sgClient1.getMailClient();
mailClient1.send(msg);

Besides the client is for all functionality of sendgrid, would prefer only for emailclient if possible.

@thinkingserious
Copy link
Contributor

Hello @aimythgit,

I believe you should use sgClient1.send(msg) as demonstrated here. This package is the closest thing we have to an email only helper library.

With best regards,

Elmer

@aimythgit
Copy link
Author

Elmer,
Thanks for the clarification but the current sendMail package is a singleton, that's why I have asked for this feature.

Either expose the mail client from this package that support instances @sendgrid/client
or allow multiple instance from the @sendgrid/mailClient package

@eshanholtz eshanholtz added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap and removed status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Jul 21, 2021
@eshanholtz
Copy link
Contributor

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.

@danmana
Copy link
Contributor

danmana commented Feb 23, 2022

While the default export of @sendgrid/mail is indeed a singleton, you can also use the class to create multiple instances like so (though the documentation does not mention it, it works perfectly):

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

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: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

5 participants