Send and verify emails with the Mailrify Node.js SDK.
import Mailrify from 'mailrify'; const client = new Mailrify(process.env.MAILRIFY_SECRET_KEY as string);
const result = await client.emails.send({ to: '[email protected]', from: { name: 'Mailrify Demo', email: '[email protected]' }, subject: 'Welcome', body: '<h1>Hello</h1><p>Your SDK setup is working.</p>' }); console.log(result.success, result.data.timestamp);
to
await client.emails.send({ to: [ '[email protected]', { name: 'Two', email: '[email protected]' } ], from: '[email protected]', subject: 'Product update', body: '<p>New features are live.</p>' });
await client.emails.send({ to: '[email protected]', from: '[email protected]', template: 'tmpl_123', data: { firstName: 'John', plan: 'premium' } });
await client.emails.send({ to: '[email protected]', from: '[email protected]', subject: 'Your invoice', body: '<p>Invoice attached.</p>', attachments: [ { filename: 'invoice.pdf', content: 'JVBERi0xLjQKJ...', contentType: 'application/pdf' } ] });
await client.emails.send({ to: '[email protected]', from: { name: 'Growth Team', email: '[email protected]' }, subject: 'Release notes', body: '<p>Monthly update.</p>', reply: '[email protected]', name: 'Monthly newsletter', subscribed: true, headers: { 'X-Campaign-Id': 'monthly-2026-03' } });
const verification = await client.emails.verify('[email protected]'); console.log(verification.data.valid); console.log(verification.data.isRandomInput); console.log(verification.data.reasons);
const verification = await client.emails.verify('[email protected]'); if (verification.data.isTypo && verification.data.suggestedEmail) { console.log('Did you mean:', verification.data.suggestedEmail); }