helios-send-next
v0.2.0
Published
Next.js helpers for HeliosSend email delivery service
Maintainers
Readme
helios-send-next
Next.js helpers for HeliosSend email delivery service, built by Revinity.
Installation
npm install helios-send-next
# or
pnpm add helios-send-next
# or
yarn add helios-send-nextQuick Start
Create an API route handler:
// pages/api/sendEmail.ts
import { createHandler } from 'helios-send-next';
export default createHandler({
apiKey: process.env.HELIOS_API_KEY!,
baseUrl: 'https://api.helios-send.com',
});Then call it from your frontend:
// pages/contact.tsx
import { useState } from 'react';
export default function ContactPage() {
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
try {
const res = await fetch('/api/sendEmail', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
from: { email: '[email protected]', name: 'My App' },
to: [{ email: '[email protected]' }],
subject: 'Contact Form',
html: '<p>New contact form submission</p>',
}),
});
if (res.ok) {
alert('Email sent!');
}
} catch (error) {
console.error('Failed to send email:', error);
} finally {
setLoading(false);
}
};
return (
<form onSubmit={handleSubmit}>
<button type="submit" disabled={loading}>
{loading ? 'Sending...' : 'Send Email'}
</button>
</form>
);
}Features
- Secure API key handling (server-side only)
- Type-safe with TypeScript
- Easy integration with Next.js API routes
- Works with App Router and Pages Router
Template Design with HeliosEditor
Design templates with HeliosEditor and send them:
// In your API handler or component
await fetch('/api/sendEmail', {
method: 'POST',
body: JSON.stringify({
from: { email: '[email protected]' },
to: [{ email: '[email protected]' }],
templateId: 'welcome-template-123',
substitutions: {
userName: 'John Doe',
},
}),
});