refire-client
v0.1.3
Published
Refire Email API Client
Downloads
496
Maintainers
Readme
Refire Email Client
A lightweight TypeScript client for sending transactional emails through the Refire Email API.
Getting Your API Key
Before using the client, you'll need an API key:
- Create a company account in the Refire dashboard
- Navigate to your company view page
- Find your API key in a secure, masked input field
- Click the field to copy your API key to clipboard
Keep your API key secure and never share it publicly or commit it to version control.
Installation
npm install refire-client
Usage
Initialize the Client
import { Refire } from "refire-client";
const refire = new Refire({
apiKey: "your-api-key",
});
You can optionally specify a custom API URL during initialization:
const refire = new Refire({
apiKey: "your-api-key",
apiUrl: "https://api.refire.email/v1",
});
Sending Basic Emails
To send a basic email without a template:
refire.sendEmail({
to: "[email protected]",
subject: "Hello",
name: "John Doe",
message: "Your email content here",
});
Sending Template-Based Emails
To send an email using a pre-defined template:
refire.sendEmailFromTemplate({
to: "[email protected]",
templateId: "<your_template_id>",
});
Method Chaining
You can also use method chaining if preferred:
Sending a basic email:
new Refire("<your_api_key>").sendEmail({
to: "[email protected]",
subject: "Hello",
name: "John Doe",
message: "Your email content here",
});
Sending a template-based email:
new Refire("<your_api_key>").sendEmailFromTemplate({
to: "[email protected]",
templateId: "<your_template_id>",
});
API Reference
SendEmailParams
Parameters for sending a basic email:
to
(string): Recipient email addresssubject
(string): Email subject linename
(string): Recipient namemessage
(string): Email content
SendEmailFromTemplateParams
Parameters for sending a template-based email:
to
(string): Recipient email addresstemplateId
(string): ID of the template to use
Error Handling
The client includes built-in error handling. Both sendEmail
and sendEmailFromTemplate
methods will throw an error if the API request fails:
try {
await refire.sendEmail({
to: "[email protected]",
subject: "Hello",
name: "John Doe",
message: "Your email content here",
});
} catch (error) {
console.error("Failed to send email:", error);
}
License
MIT
Author
For more information and detailed documentation, visit refire.email.