Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/dexterdmonkey/go-smtp

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/dexterdmonkey/go-smtp

  • v1.0.0-1a
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-smtp

go-smtp is a Go library for sending emails via SMTP. It provides an easy-to-use interface for sending emails with support for custom authentication, TLS, and more.

Installation

To install the library, use go get:

go get github.com/dexterdmonkey/go-smtp

Usage

Here's a simple example of how to use the go-smtp library:

package main

import (
	"fmt"

	"github.com/dexterdmonkey/go-smtp"
)

func main() {
	var mail smtp.Interface

	SMTPUser := "your@email.com"
	SMTPPassword := "yourpassword"
	SMTPHost := "smtp.email.com"
	SMTPPort := 587

	mail, err := smtp.New(
		SMTPUser,
		SMTPPassword,
		SMTPHost,
		SMTPPort,
	)

	if err != nil {
		fmt.Println("error; ", err.Error())
		return
	}

	err = mail.SendMail(smtp.Email{
		To:      []string{"recipient1@email.com"},
		Subject: "subject",
		Body:    "body",
	})

	if err != nil {
		fmt.Println("error; ", err.Error())
		return
	}

	err = mail.SendMail(smtp.Email{
		To:      []string{"recipient2@email.com"},
		Subject: "subject",
		Body:    "body",
	})

	if err != nil {
		fmt.Println("error; ", err.Error())
		return
	}

	fmt.Println("Success")
}

API

Types

Interface

The Interface defines the methods available for the SMTP client:

type Interface interface {
	GetSenderAddress() string
	GetPassword() string
	GetHost() string
	GetPort() int
	ParseBody(body string, parameters map[string]interface{}) string
	SendMail(email Email) error
}
Email

The Email struct represents an email to be sent:

type Email struct {
	To      []string
	Cc      []string
	Bcc     []string
	Subject string
	Body    string
}

Functions

New

Creates a new SMTP client:

func New(senderAddress, password, host string, port int) (*SMTP, error)
GetSenderAddress

Returns the sender address:

func (c *SMTP) GetSenderAddress() string
GetPassword

Returns the password:

func (c *SMTP) GetPassword() string
GetHost

Returns the host:

func (c *SMTP) GetHost() string
GetPort

Returns the port:

func (c *SMTP) GetPort() int
GetClient

Returns an authenticated SMTP client:

func (c *SMTP) GetClient() (*smtp.Client, error)
SendMail

Sends an email:

func (c *SMTP) SendMail(email Email) error
ParseBody

Parses the body of the email with the provided parameters:

func (c *SMTP) ParseBody(body string, parameters map[string]interface{}) string

License

This library is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

FAQs

Package last updated on 06 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc