...

Package mailer

import "gitlab.hexacode.org/go-libs/mailer"
Overview
Index
Subdirectories

Overview ▾

Example:

```go

package main

import (

"gitlab.hexacode.org/go-libs/hctypes"
"gitlab.hexacode.org/go-libs/mailer"

)

func main() {
  // Create a new template
  // Please see https://github.com/noirbizarre/gonja for more details template
  tmpl, err := mailer.NewTemplate("Hello {{ name }}!")
  if err != nil {
    panic(err)
  }

  // Create a new sender
  sender := mailer.NewSender("Example Sender", "example-sender@gmail.com", "password", "smtp.gmail.com", 587, tmpl)

  // Send an email
  err = sender.SendEmail("example-recipient@gmail.com", "Example Subject", hctypes.Dict{"name": "John Doe"})
  if err != nil {
    panic(err)
  }
}

```

type Sender

Sender represents a mail sender

type Sender struct {
    Template *Template // The template *Template
    // contains filtered or unexported fields
}

func NewSender

func NewSender(sender_name, sender_address, password, smtp_host string, smtp_port int, template *Template) *Sender

NewSender creates a new Sender

sender_name: The name of the sender sender_address: The email address of the sender password: The password of the sender smtp_host: The smtp host (eg: smtp.gmail.com) smtp_port: The smtp port (eg: 587) template: The template *Template Returns: *Sender

func (*Sender) SendEmail

func (s *Sender) SendEmail(to, subject string, query hctypes.Dict) error

SendEmail sends an email

to: The email address of the recipient subject: The subject of the email query: The query of the email template Returns: error

type Template

Template represents a mail template

type Template struct {
    // contains filtered or unexported fields
}

func NewTemplate

func NewTemplate(template string) (*Template, error)

NewTemplate creates a new Template

template: The template Returns: *Template

func NewTemplateFromFile

func NewTemplateFromFile(template_file string) (*Template, error)

NewTeplateFromFile creates a new Template

template_file: The template file Returns: *Template

func (*Template) Render

func (t *Template) Render(data hctypes.Dict) (string, error)

Render renders the template

data: The data Returns: string

Subdirectories

Name Synopsis
..
example