1
6 Comments

Static Website Landing Page + Mailer API

Hi all,

I am building my landing page from scratch (using a reactjs template). I deployed the site as a static site and trying to configure the "Subscribe" or "Sign up for early access".

I configured Big Mailer (as they have free tier with 1000 contacts), connected my form to send an API request to create contact (access of API key is restricted to create only, no read/update/delete so I'm okay with this API key being public), but getting a CORS error. I tried using "mode: no-cors" but that doesn't work either.

I couldn't find any documentation on Big Mailer site regarding CORS and typically that's a server side change to accept requests from my site (although currently just localhost).

Any thoughts on how to proceed or other email providers that could just collect my subscribers?

For context, here is my code:

    const request: BigMailerRequest = {
      unsubscribe_all: false,
      email: subscriber.email,
      field_values: [
        { name: "FIRST_NAME", string: firstName ?? "" },
        { name: "LAST_NAME", string: lastName ?? "" },
        { name: "CLICKED_SIGN_UP", string: String(siteStorage.clickedSignup) },
        { name: "WATCHED_VIDEO", string: String(siteStorage.clickedWebsiteVideo) },
        { name: "SOURCE", string: subscriber.source },
      ],
    }

    return new Promise((resolve, reject) => {
      fetch(`https://api.bigmailer.io/v1/brands/{omitted}/contacts`, {
        method: "POST",
        mode: "no-cors",
        body: JSON.stringify(request),
        headers: {
          accept: "application/json",
          "content-type": "application/json",
          "X-API-Key": "{omitted}",
        },
      })
        .then(() => {
          resolve()
        })
        .catch((e) => {
          console.log(e, e)
          reject(e)
        })
    })

Thanks,

on October 11, 2023
  1. 1

    The simplest way to implement this is to create a form on BigMailer and embed the provided HTML of the form into your static page. Use of API via frontend is not allowed for security reasons. Your API key can be abused* in the future, once captured.

    You can also use BigMailer's free landing pages (with forms for email collection) to host your landing page. You can host a 3-page site on your domain completely for free.

    Reach out via BigMailer live chat (7 days a week) with any questions.

    *Hackers/scammers often sign people up to flood their inboxes with welcome emails to make the purchase confirmations harder to see and with your API key they can do this in bulk.

    1. 1

      Thanks @webbie, I didn't notice you had responded. I ended reaching out to BigMailer support and they suggested the same thing.

      It makes sense why you wouldn't want to expose the API key for security reasons.

      After taking advice from support, I successfully added BigMailer integration to my site. https://startsmallkit.com/

      Unfortunately I will not be keeping that domain name, but it's up until I can change the page around.

  2. 1

    I don't know exactly how BigMailer works but most probably, they asked for and you configured a domain name in order to use their service. Which means it will only work when the requests are made for that domain.

    The 'cors' option that you're trying to set should be set from the server (their end) if you send it from your frontend, it's just gonna result into an opaque response, no need to enter details here.

    So, my guess is, they do have CORS enabled (as seen in the error) and in order for you to bypass that error, all their server needs is that the request comes from the frontend registered (your domain) because this is now in their back system and 'whitelisted'.

    On short, calling this from the deployed site should work and not throw an error. They might also have some documentation for localhost testing.

    1. 1

      Rusu, thank you for the tips. I proceeded to configure the account which involves setting up an Amazon SES. I don't think there is a setup for domain, but if I can't find more I will contact their support directly.

  3. 0

    Great post! It's always wonderful to see people sharing their knowledge and insights with the community.
    Keep up the good work!

    1. 1

      Thanks for the reply @Isabela342!

      As webbie mentioned in the above comment (https://www.indiehackers.com/post/static-website-landing-page-mailer-api-e1d8693bc6?commentId=-NgZGiaz7cQdG4Rkig9s) I successfully configured my static webpage with BigMailer integration.

      I'm happy to share details.

      Specifically, I added three locations (three separate forms).

      1. Sign-up link on top right - asks for more information
      2. Hero section you can subscribe - email only
      3. Mailing list section at bottom - email only

      Although I probably could have done a single form, it was easy enough to create three and hardcode a property called "Source":

      • "Signup"
      • "Subscribe"
      • "Mailing List"