Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Latest commit

 

History

History
66 lines (53 loc) · 1.74 KB

README.md

File metadata and controls

66 lines (53 loc) · 1.74 KB

This package provides a simple interface to send emails for HacKSU and Kent Hack Enough.

Supports email templates, React JSX, markdown, Sass, and more.

Example Usage

import { Email, EmailTemplate, Stylesheet, Sendgrid, SUBSTITUTION_TAG } from '@hacksu/email';

// used to deliver Email objects as actual mail
const SendgridDelivery = new Sendgrid('SENDGRID_API_KEY', {
    // sendgrid mail parameters
    // these will get applied to each email sent through this instance
    from: '[email protected]',
})


// Including stylesheets in react emails
const HacksuMailingStyles = Stylesheet('@email/welcome.scss') 
// @email/... refers to @hacksu/email/src/styles/...
// You can also pass in relative paths that will be relative to current script

// Stylesheets can also be merged together and stringified
const SomeStyles = Stylesheet(
    Stylesheet('./style.scss') + HacksuMailingStyles
);


// deliver a markdown email
SendgridDelivery.send(new Email({
    from: "[email protected]',
    to: '[email protected]',
    subject: "hi there!",
    content: `
# Title 1
## Title 2
Content

<a href="%unsubscribe%">unsubscribe</a>
    `
}))


// react JSX email template
// substitution tags are %field%, or SUBSTITUTION_TAG(field)
const WelcomeTemplate = EmailTemplate({
    subject: "Welcome to HacKSU!",
    content: (<div>
        <HacksuMailingStyles/>
        <h1>Hey %name%! %subject</h1>
        <a href={SUBSTITUTION_TAG('unsubscribe')}>
            unsubscribe from our emails
        </a>
    </div>)
})

// deliver the email
SendgridDelivery.send(new WelcomeTemplate({
    to: '[email protected]',
    name: 'Joe',
}), {
    // sendgrid fields (such as from, to, subject)
    // can also be applied here rather than directly
    // on the email instance itself
})