stupidsimplemailer

command module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 13 Imported by: 0

README

#+title: Stupid Simple Mailer

Stupid Simple Mailer is a configurable email sender backend for your email form.

*** Why?
Often times if you want to make a simple email form for your portfolio site you'd need to make your own backend from scratch, which is a chore.

Stupid Simple Mailer provides configurable email sender, with which you can make an email backend in less than 20 lines of yaml.
*** How it works
1. Configure

   You need to provide configuration inside of `config.yml`.
   #+begin_src yaml
    port: 8080
    services:
        - endpoint: /test
          email: example@gmail.com # email to send from
          env: PW # Environment variable where your password is stored
          to: # default destination when not specified by request
             - test@gmail.com
        # Format with wich the body of the email that will be sent using go template
          bodyFormat: |
              {{.body}}
              {{.name}}, {{.email}}
          cors: "*" # Cors header
          smtpServer: smtp.gmail.com # server
          smtpPort: "587" # port
          CC: # CC (optional)
            - cc@gmail.com
          BCC: # BCC (optional)
            - bcc@gmail.com
        - endpoint: test2
          # ....... repeat for multiple endpoints
    ]
   #+end_src

   Services is an array so you can make multiple endpoints
2. Environment

    You can provide the environment variable by yourself, SSM can also read .env file.
    #+begin_src bash
    # either in .bashrc or .env
    export PW=yourverysecretpassword
    #+end_src
3. Request

    Your Frontend can now send a request to your SSM backend.
    SSM will read the json body of the request.
    These are the default json field that SSM uses
    #+begin_src json
    {
    "subject": "the subject of the email",
    "to": "email@gmail.com, commaseperated@gmail.com",
    "bcc": "bcc@gmail.com",
    "cc": "cc@gmail.com"
    }
    #+end_src
    Furthermore, SSM will read theld that is required by your bodyFormat in the config.

    For example, the config above will read the fields "body", "name", and `"email" and put it accordingly.


*** BodyFormat
Body will be the email body. This uses the go templating language. You can read more here: https://blog.gopheracademy.com/advent-2017/using-go-templates/

The field names in the template will be read from the request body. You can name the field name whatever you want.
In the examle above the fields "body", "name", and "email" will be read, and be put into the body.
*** How to use
**** Install
***** From Source
      #+begin_src bash
      git clone https://github.com/Ghibranalj/ssm.git
      cd ssm
      go build .
      #+end_src
***** With go install
#+begin_src bash
     go install github.com/ghibranalj/ssm@latest
#+end_src

**** CLI
#+begin_src bash
ssm -c config.yml -e .env
#+end_src

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL