Code Monkey home page Code Monkey logo

mailit's Introduction

Mailit

An email kit for golang to be reused across different projects.

Introduction

Mailit is an easy to use mail library to send emails.

Features

Mailit supports:

  • Plain text emails
  • Text / HTML template based emails
  • Attachments
  • Sending emails to multiple recipients

Requirements

  • Go 1.5

Documentation

https://pkg.go.dev/github.com/wisdommatt/mailit


We also recommend you use the how to guide on this page because Mailit does basically two things:

  • Send Plain Text Emails
  • Send Template Based Emails

How To Use Mailit

Feel free to copy and paste the codes

  • Step 1: Initialize a mailer variable and pass in SMTP configs.

    Note: This is usually done just once

        smtpConf := mailit.SMTPConfig{
            Host:     "domain.com",
            Port:     563,
            Username: "[email protected]",
            Password: "*********",
        }
        mailer := mailit.NewMailer(smtpConf)
  • Step 2: Send email

    Sending plain text email
        textDep := mailit.TextDependencies{
            From:        "[email protected]",
            To:          []string{"[email protected]", "[email protected]", "[email protected]"},
            Subject:     "Welcome to Mailit",
            Body:        "Message Body",
            Attachments: []string{"attachments/1.txt", "attachments/2.txt"},
        }
        err := mailer.SendText(textDep)

    Sending HTML template email
        tempDep := mailit.TemplateDependencies{
            From:        "[email protected]",
            To:          []string{"[email protected]", "[email protected]", "[email protected]"},
            Subject:     "Welcome to Mailit",
            ContentType: "text/html",
            Template: "templates/welcome.html",
            TemplateData: "Any data",
            Attachments: []string{"attachments/1.txt", "attachments/2.txt"},
        }
        err := mailer.SendTemplate(tempDep)

    Sending Text template email
        tempDep := mailit.TemplateDependencies{
            From:        "[email protected]",
            To:          []string{"[email protected]", "[email protected]", "[email protected]"},
            Subject:     "Welcome to Mailit",
            ContentType: "text/plain",
            Template: "templates/sample.txt",
            TemplateData: struct{
                Name, Email string
            }{
                Name: "Wisdom Matt",
                Email: "[email protected]",
            },
            Attachments: []string{"attachments/1.txt", "attachments/2.txt"},
        }
        err := mailer.SendTemplate(tempDep)

NOTE: You will access the template data the way it is access usually in Go templates e.g {{ .Name }} or {{ .Email }}


Dependencies

Testing

This package uses manual testing because the gomail package which it depends on used core types instead of interfaces which in turn makes it difficult to test, a thorough test is done before any changed is made on the project so there is nothing to be scared of.

License

MIT

Author / Contact

Wisdom Matthew - github.com/wisdommatt

Feel free to email me at [email protected]

mailit's People

Contributors

wisdommatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.