Skip to content

Small go package to generate and read temporary emails

Notifications You must be signed in to change notification settings

snopan/tmpmailgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tmpmailgo

Small package that uses 1sec Mail to generate temporary emails to receive messages

Install

go get github.com/snopan/tmpmailgo

Usage

Simple use case to generate email and receive certain email

// Create a new email
email, err := tmpmailgo.NewEmail()
if err != nil {
  panic(err)
}

// Continously check if message have arrived
var messageID int
tk := time.NewTicker(2 * time.Second)
for range tk.C {

  // Read inbox that contains list of message summary
  inbox, err := email.GetInbox()

  // Check each message whether we have recieved the specifc email
  foundMessage := false
  for _, message := range inbox {
    if message.From == "[email protected]" {
      messageID = message.ID
      foundMessage = true
      break
    }
  }

  // Stop wait loop when message is found
  if foundMessage {
  	break
  }
}

// Get more detail with message id
fullMessage, err := email.ReadMessage(messageID)
if err != nil {
	panic(err)
}

About

Small go package to generate and read temporary emails

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages