sendinblue / APIv3-nodejs-library

SendinBlue's API v3 Node.js Library
ISC License
101 stars 47 forks source link

Can't figure out how to send email in nodejs. #40

Closed aberba closed 6 years ago

aberba commented 6 years ago

Can you guys show an actual example for sending an email in nodejs with the API? Docs looks confusing.

ekta-slit commented 6 years ago

Hi @aberba

Below is the sample to send transactional email

var SibApiV3Sdk = require('sib-api-v3-sdk');

var defaultClient = SibApiV3Sdk.ApiClient.instance;

var apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = "YourApiV3Key"

var apiInstance = new SibApiV3Sdk.SMTPApi();

var sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail(); // SendSmtpEmail | Values to send a transactional email

sendSmtpEmail.to = [{ "email":"to@domain.com", "name":"toName"}];
sendSmtpEmail.sender = { "email":"sender@domain.com", "name":"sender"};
sendSmtpEmail.htmlContent = "This is test content";
sendSmtpEmail.subject = "My Subject";
sendSmtpEmail.headers = {"x-mailin-custom":"myV3Custom" };
sendSmtpEmail.tags = ["myTag1","myTag2"];
sendSmtpEmail.attachment =  [{"url": "https://example.com/ValidimageUrl1.jpg"},{"url": "https://example.com/ValidimageUrl2.jpg"}]

apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
  console.log('API called successfully. Returned data: ' + data);
}, function(error) {
  console.error(error);
});

refer: https://github.com/sendinblue/APIv3-nodejs-library/blob/master/docs/SendSmtpEmail.md doc: https://developers.sendinblue.com/v3.0/reference#sendtransacemail

Also please suggest how can we improve our doc.

Thanks

Abhijeetjaiswalit commented 5 years ago

@ekta-slit can you please tell me how we will send params(e.g, emai, name, phone etc) along with templaeId. and how we will replace them on sendinblue(on template) side?

nstuyvesant commented 5 years ago

Hi @ekta-slit,

Can we pass in the values using a constructor like this (also not in JSON)...

let sendSmtpEmail =  new SibApiV3Sdk.SendSmtpEmail({
    to: [{ email: 'to@domain.com', name: 'toName'}],
    sender: { email: 'sender@domain.com', name: 'sender'},
    htmlContent: 'This is test content',
    subject: 'My Subject',
    tags: ['myTag1', 'myTag2']
  });

Thanks, Nate

nstuyvesant commented 5 years ago

I can answer my own question:

  1. The SibApiV3Sdk.SendSmtpEmail does not provide a constructor
  2. The values do not need to be in JSON format
CezarCobuz commented 4 years ago

Would any of you be so kind to continue the example from @ekta-slit with an attachment in base64? sendSmtpEmail.attachment = ..... for name and base64 encoded

Themba-Stacks commented 4 years ago

@ekta-slit, Hi So I think a way that you can improve your documentation is by having code implementations, for example with the SendSmtpEmail(), the name is straight forward but I didn't know how to use it with the rest of the code. Also a bit more explanation on how everything ties together.