notify

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 12 Imported by: 0

README

Email Notifier Usage

Inline Images in Templates

To embed images directly into the email body (inline images):

  1. Pass the image file path when calling the Send method.
  2. Reference the image in your HTML template using cid:<filename>.
Example

Suppose you have an image named logo.png that you want to include in the email.

1. Go Code

Pass the absolute path to logo.png as an attachment argument to Send.

// ... initialize notifier ...

// Send email with "welcome" template and attach logo.png
err := notifier.Send("welcome", data, "/path/to/assets/logo.png")
if err != nil {
    // handle error
}

The Send method logic (in smtp.go) automatically detects that logo.png is an image and sets its Content-ID to the filename logo.png.

2. HTML Template Configuration

In your EmailTmpl configuration, use cid:logo.png in the src attribute of the <img> tag.

notifier.Template = map[string]*notify.EmailTmpl{
    "welcome": {
        Subject: "Welcome to our Service",
        // Use 'cid:' followed by the filename (base name) of the attached image
        Body: `
            <html>
                <body>
                    <h1>Hello, {{.Name}}</h1>
                    <p>Here is our logo:</p>
                    <img src="cid:logo.png" alt="Company Logo" />
                </body>
            </html>
        `,
        Receivers: []string{"user@example.com"},
    },
}
Note
  • The Content-ID is generated from the base filename of the attachment (e.g., filepath.Base("/path/to/assets/logo.png") -> logo.png).
  • Ensure the filename in cid:<filename> matches exactly with the attached file's name.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailNotifer

type EmailNotifer struct {
	Logger *zap.Logger
	From   string
	//Receivers []string
	SMTP     SmtpSettings
	Template map[string]*EmailTmpl
	Once     sync.Once
}

func (*EmailNotifer) PostInit

func (en *EmailNotifer) PostInit() error

func (*EmailNotifer) Send

func (en *EmailNotifer) Send(tmpl string, data map[string]interface{}, attachments ...string) error

type EmailTmpl

type EmailTmpl struct {
	Subject string
	Body    string
	// Notfound string
	Receivers    []string
	CcReceivers  []string
	BccReceivers []string
	// contains filtered or unexported fields
}

type SmtpSettings

type SmtpSettings struct {
	Host     string
	Port     int
	Username string
	Password string
	Tls      bool
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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