tmm

package module
v0.0.0-...-a49814f Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 13 Imported by: 1

README

tmm

Go Reference

Tiny package that uses 10MinuteMail to generate temporary email addresses. Supports receiving, forwarding and replying to messages.

Dependencies

This library depends on the uTLS package, a fork of crypto/tls that supports custom TLS ClientHello specifications.

Install

Try the example program and get a mail proxy running in seconds:

$ go install github.com/shellhazard/tmm/cmd/mailwatch
$ mailwatch -fwd=realmail@example.com
Your address is: fuzxptvvkwpdbalcek@sdvft.com
Waiting for new messages.

Or get stuck in:

go get github.com/shellhazard/tmm

Usage

Short example for a common use case:

// Create a new session
s, err := tmm.New()
if err != nil {
	panic(err)
}

// Get the email string
addr := s.Address()

// <register a new account with a service etc. here>

// Wait for verification email to come through
var received tmm.Message

tk := time.NewTicker(2 * time.Second)
for range tk.C {
	mail, err := s.Latest()
	if err != nil {
		panic(err)
	}

	for _, m := range mail {
		if m.Sender == "noreply@example.org" {
			// We've got our email!
			received = m
			break
		}
	}
}

body := received.Plaintext

// <parse body, click any links etc.>

Documentation

Overview

Package tmm provides a simple interface to the 10MinuteMail web service.

  // Create a new session
  s, err := tmm.New()
  if err != nil {
	   log.Fatal(err)
  }

  // Check the email address
  addr := s.Address()

  // Retrieve all messages
  mail, err := s.Messages()
  for _, m := range mail {
	   fmt.Println(mail.Plaintext)
  }

Index

Constants

View Source
const (
	DefaultTimeout   = 10 * time.Second
	DateLayout       = "2006-01-02T15:04:05.999999999Z0700"
	DefaultUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
)

Variables

View Source
var (
	ErrBuildingRequest = errors.New("failed to construct request object")
	ErrRequestFailed   = errors.New("request to 10minutemail failed")
	ErrReadBody        = errors.New("reading response body failed")
	ErrMarshalFailed   = errors.New("marshalling request body failed")
	ErrUnmarshalFailed = errors.New("unmarshalling response body failed")
	ErrMissingSession  = errors.New("missing session cookie in response")
	ErrBlockedByServer = errors.New("server is blocking requests from this host; probably rate limited")
)

Functions

This section is empty.

Types

type Message

type Message struct {
	// The unique ID of the message on 10MinuteMail.
	// Not permanent.
	ID string `json:"id"`
	// The time the message was sent at.
	SentDate time.Time `json:"sentDate"`
	// The email address of the sender of the message.
	Sender string `json:"sender"`
	// The subject of the email.
	Subject string `json:"subject"`
	// The email body as received in plaintext, with HTML stripped.
	Plaintext string `json:"plaintext"`
	// The email body with HTML tags included.
	HTML string `json:"html"`
	// A short preview of the message body.
	Preview string `json:"preview"`
}

Message represents a single email message sent to a temporary mail.

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

type Session

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

Session holds information required to maintain a 10MinuteMail session.

func New

func New() (*Session, error)

New creates a new 10MinuteMail session with a random address.

func NewWithClient

func NewWithClient(c *http.Client) (*Session, error)

NewWithClient is identical to New but allows for passing a custom HTTP client object.

func (*Session) Address

func (s *Session) Address() string

Address returns the email address attached to the current session.

func (*Session) Expired

func (s *Session) Expired() bool

Expired returns whether or not the session is due to have expired and is in need of renewal.

func (*Session) ExpiresAt

func (s *Session) ExpiresAt() time.Time

ExpiresAt returns a time.Time object representing the instant in time that the session is due to expire.

func (*Session) Forward

func (s *Session) Forward(messageid, recipient string) (bool, error)

Forward asks 10MinuteMail to forward the message with the provided ID to the provided recipient address.

Returns a bool indicating whether or not the forward request was issued successfully and an error if issues were encountered while making the request.

Note that the server will claim to be successful even if the recipient address is invalid or the mail gets rejected after sending.

func (*Session) Latest

func (s *Session) Latest() ([]Message, error)

Latest contacts the server and returns a list of any messages that haven't already been received by this session.

func (*Session) Messages

func (s *Session) Messages() ([]Message, error)

Messages contacts the server and returns a list of all messages received to the email address attached to this session.

Note that if any new messages are found, the same counter will be updated that is used when calling the session.Latest() method, so you won't need to call it afterwards.

func (*Session) Renew

func (s *Session) Renew() (bool, error)

Renew attempts to extend the session by an additional 10 minutes.

Returns a bool indicating whether the server indicated that the reset was successful or not and an error if issues were encountered while making the request.

func (*Session) Reply

func (s *Session) Reply(messageid, body string) (bool, error)

Reply asks 10MinuteMail to send a reply to the email that sent the message with the provided ID, with the provided body.

Returns a bool indicating whether or not the reply was issued successfully - failure generally means the message is too old - and an error if issues were encountered while making the request.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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