Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
167 lines (129 sloc) 4.4 KB
description
Sends the latest post from the RSS feed to the Netlify subscribers

Mailer - Github

dependenciesversion commit license

{% embed url="https://andre.gg/git/mailer" caption="Source code here" %}

Prerequisites

Git and Node.js will need to be installed. You will need a decent Code Editor. And also a decent understanding of the Command Line Interface. (Powershell works fine on Windows)

Setup

This was designed for my Netlify Blog that had an RSS feed. It grabs the subscriptions from the blog and emails the subscribers about my most recent post.

To create the contact form use this snippet:

<form name="subscribe" method="POST" data-netlify="true">
    <p>
        <label>Your Name: <input type="text" name="name" minlength="3" required/></label>   
    </p>
    <p>
        <label>Your Email: <input type="email" name="email" required/></label>
    </p>
    <p>
        <button type="submit">Send</button>
    </p>
</form>

To download the code use this command:

git clone https://github.com/andrejarrell/Mailer.git mailer

Open the directory and install the required dependencies.

cd mailer
npm i

Create a file named .env

{% code title=".env" %}

# You can create a token here:
# https://app.netlify.com/user/applications/personal

NETLIFY_TOKEN=

# Most SMTP providers offer generous free tiers (I use gmail)

SMTP_HOST=
SMTP_USER=
SMTP_PASS=

# The current domain of your site (ex: blog.andre.gg)

SITE_DOMAIN=

# The email you want to send as and for people to reply to

YOUR_EMAIL=

{% endcode %}

Fill in the required settings (no quotes needed in .env file)

Run

node index.js

Email

Example of what the email looks like when it is sent

API

{% api-method method="get" host="https://api.netlify.com/api/v1/sites/" path=":site/submissions" %} {% api-method-summary %}

{% endapi-method-summary %}

{% api-method-description %} Get form submissions from Netlify site {% endapi-method-description %}

{% api-method-spec %} {% api-method-request %} {% api-method-path-parameters %} {% api-method-parameter name="site" type="string" required=true %} Site API Id or site domain {% endapi-method-parameter %} {% endapi-method-path-parameters %}

{% api-method-query-parameters %} {% api-method-parameter name="access_token" type="string" required=true %} Access token for API {% endapi-method-parameter %} {% endapi-method-query-parameters %} {% endapi-method-request %}

{% api-method-response %} {% api-method-response-example httpCode=200 %} {% api-method-response-example-description %}

{% endapi-method-response-example-description %}

[
    {
        "number": 1,
        "title": "Andre Jarrell",
        "email": "mail@andre.gg",
        "name": "Andre Jarrell",
        "first_name": "Andre",
        "last_name": "Jarrell",
        "company": null,
        "summary": "<strong>Andre Jarrell</strong> ",
        "body": null,
        "data": {
            "name": "Andre Jarrell",
            "email": "mail@andre.gg",
            "ip": "99.132.88.296",
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36",
            "referrer": "https://blog.andre.gg/"
        },
        "created_at": "2019-03-31T07:48:56.548Z",
        "human_fields": {
            "Name": "Andre Jarrell",
            "Email": "mail@andre.gg",
        },
        "ordered_human_fields": [
            {
                "title": "Name",
                "name": "name",
                "value": "Andre Jarrell",
            },
            {
                "title": "Email",
                "name": "email",
                "value": "mail@andre.gg",
            }
        ],
        "id": "5cajh0e87be0e66e7ja888f1",
        "form_id": "5cac708s35hd450009309g05",
        "site_url": "http://blog.andre.gg",
        "form_name": "subscribe"
    }
]

{% endapi-method-response-example %} {% endapi-method-response %} {% endapi-method-spec %} {% endapi-method %}

You can’t perform that action at this time.