Example showing how to send email
Closed this issue · 2 comments
chevdor commented
Since Sendinblue is mainly about sending email, an example showing how to send emails does not sounds crazy to me 🚨
So far, I figured out that it probably will start with:
const api_key='...'
let apiInstance = new SibApiV3Sdk.AccountApi()
apiInstance.setApiKey(AccountApiApiKeys.apiKey, api_key)
const task = new SibApiV3Sdk.SendSmtpEmail()
task.templateId = 42 // pick accordingly
task.to = [{name: 'John', email: 'john@example.com'}]
task.params = {
foo: {
bar: 69,
}
}
and then... ? :)
aayush-sib commented
Hi @chevdor
You can find the example of sendTransacEmail
in our Documentation
Example of sendTransacEmail
:
const SibApiV3Sdk = require('sib-api-v3-typescript');
let apiInstance = new SibApiV3Sdk.TransactionalEmailsApi();
let apiKey = apiInstance.authentications['apiKey'];
apiKey.apiKey = 'YOUR API KEY';
let sendSmtpEmail = new SibApiV3Sdk.SendSmtpEmail();
sendSmtpEmail.subject = "My {{params.subject}}";
sendSmtpEmail.htmlContent = "<html><body><h1>This is my first transactional email {{params.parameter}}</h1></body></html>";
sendSmtpEmail.sender = {"name":"John Doe","email":"example@example.com"};
sendSmtpEmail.to = [{"email":"example@example.com","name":"Jane Doe"}];
sendSmtpEmail.cc = [{"email":"example2@example2.com","name":"Janice Doe"}];
sendSmtpEmail.bcc = [{"name":"John Doe","email":"example@example.com"}];
sendSmtpEmail.replyTo = {"email":"replyto@domain.com","name":"John Doe"};
sendSmtpEmail.headers = {"Some-Custom-Name":"unique-id-1234"};
sendSmtpEmail.params = {"parameter":"My param value","subject":"New Subject"};
apiInstance.sendTransacEmail(sendSmtpEmail).then(function(data) {
console.log('API called successfully. Returned data: ' + JSON.stringify(data));
}, function(error) {
console.error(error);
});