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
- Variables
- type Message
- type Session
- func (s *Session) Address() string
- func (s *Session) Expired() bool
- func (s *Session) ExpiresAt() time.Time
- func (s *Session) Forward(messageid, recipient string) (bool, error)
- func (s *Session) Latest() ([]Message, error)
- func (s *Session) Messages() ([]Message, error)
- func (s *Session) Renew() (bool, error)
- func (s *Session) Reply(messageid, body string) (bool, error)
Constants ¶
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 ¶
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 ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds information required to maintain a 10MinuteMail session.
func NewWithClient ¶
NewWithClient is identical to New but allows for passing a custom HTTP client object.
func (*Session) Expired ¶
Expired returns whether or not the session is due to have expired and is in need of renewal.
func (*Session) ExpiresAt ¶
ExpiresAt returns a time.Time object representing the instant in time that the session is due to expire.
func (*Session) Forward ¶
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 ¶
Latest contacts the server and returns a list of any messages that haven't already been received by this session.
func (*Session) Messages ¶
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 ¶
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 ¶
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.