onesecmail

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 7 Imported by: 0

README

onesecmail

onesecmail is a Go library for accessing the www.1secmail.com API.

Usage

The GoDoc for this module is at: https://pkg.go.dev/github.com/z11i/onesecmail

package main

import (
    "fmt"
    
    "github.com/z11i/onesecmail"
)

func main() {
    // Generate a random mailbox name
    // The domain name can be either 1secmail.org, 1secmail.com, or 1secmail.net
    mailboxName := "randomname@1secmail.org"
    
    // Send emails to the generated email
    // ...
    
    // Create a mailbox struct for checking 1secmail
    mailbox := onesecmail.NewMailbox("randomname", "1secmail.org", nil)
    // mailbox.Address() == mailboxName
    
    // Check inbox
    mails, err := mailbox.CheckInbox()
    if err != nil {
        // handle err
    }
    
    // Read messages
    for _, mail := range mails {
        fmt.Printf("Received mail from %s with subject %s on %s\n", mail.From, mail.Subject, mail.Date)
        if mail.Subject == "subject I'm insterested in" {
            m, err := mailbox.ReadMessage(mail.ID)
            if err != nil {
                // handle err
            }
            fmt.Printf("Mail body is %s and contains %d attachments\n", m.Body, len(m.Attachments))
        }
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Domains = map[string]struct{}{
	"1secmail.com": {},
	"1secmail.org": {},
	"1secmail.net": {},
	"bheps.com":    {},
	"dcctb.com":    {},
	"kzccv.com":    {},
	"qiott.com":    {},
	"wuuvo.com":    {},
}

Functions

This section is empty.

Types

type API added in v1.0.0

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

API manages communication with the 1secmail's APIs that do not belong to a specific mailbox.

func NewAPI added in v1.0.0

func NewAPI(httpClient HTTPClient) API

NewAPI returns a new API. If nil httpClient is provided, a new http.Client will be created.

func (API) Domains added in v1.0.0

func (a API) Domains() ([]string, error)

func (API) RandomAddresses added in v1.0.0

func (a API) RandomAddresses(count int) ([]string, error)

func (API) UpdateDomains added in v1.0.0

func (a API) UpdateDomains() error

UpdateDomains updates the list of domains that 1secmail supports. This is useful if the list of domains have changed since this library was last updated.

type Attachment

type Attachment struct {
	Filename    string `json:"filename"`
	ContentType string `json:"contentType"`
	Size        int    `json:"size"`
}

Attachment represents an attachment in a 1secmail mail.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is an interface that makes an HTTP request.

type Mail

type Mail struct {
	ID          int          `json:"id"`
	From        string       `json:"from"`
	Subject     string       `json:"subject"`
	Date        string       `json:"date"`
	Attachments []Attachment `json:"attachments,omitempty"`
	Body        *string      `json:"body,omitempty"`
	TextBody    *string      `json:"textBody,omitempty"`
	HTMLBody    *string      `json:"htmlBody,omitempty"`
}

Mail represents a mail in a 1secmail inbox.

type Mailbox

type Mailbox struct {
	Login  string
	Domain string
	API
}

Mailbox manages communication with the 1secmail's APIs that belong to a specific mailbox.

func NewMailbox

func NewMailbox(login, domain string, httpClient HTTPClient) (Mailbox, error)

NewMailbox returns a new Mailbox. Use login and domain for the email handler that you intend to use. Login is the email username. If nil httpClient is provided, a new http.Client will be created.

func NewMailboxWithAddress added in v1.0.0

func NewMailboxWithAddress(address string, httpClient HTTPClient) (Mailbox, error)

NewMailboxWithAddress returns a new Mailbox. It accepts an email address that refers to a 1secmail mailbox. This is easier to use than NewMailbox if you already have an email address. If nil httpClient is provided, a new http.Client will be created.

func (Mailbox) Address

func (m Mailbox) Address() string

Address returns the email address of a Mailbox.

func (Mailbox) CheckInbox

func (m Mailbox) CheckInbox() ([]*Mail, error)

CheckInbox checks the inbox of a mailbox, and returns a list of mails.

func (Mailbox) DownloadAttachment added in v1.0.0

func (m Mailbox) DownloadAttachment(messageID int, filename string) ([]byte, error)

func (Mailbox) ReadMessage

func (m Mailbox) ReadMessage(messageID int) (*Mail, error)

ReadMessage retrieves a particular mail from the inbox of a mailbox.

Jump to

Keyboard shortcuts

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