Skip to content
Nathan Osman edited this page May 7, 2016 · 3 revisions

Using Hectane in a Go application to send emails is extremely easy.

Setup

  1. Import Hectane's queue package:

     import "github.com/hectane/hectane/queue"
    
  2. Create a queue.Config instance, specifying the directory where emails should be stored while awaiting delivery:

     cfg := &queue.Config{
         Directory:              '/some/dir/...',
         DisableSSLVerification: true,
     }
    

    Note: leaving DisableSSLVerification at its default value (false) can cause delivery problems since quite a few common SMTP servers are configured incorrectly.

  3. Create a queue.Queue instance, passing the queue.Config from the previous step:

     q, err := queue.NewQueue(cfg)
    
  4. The queue will continue to run until stopped:

     q.Stop()
    

    Note: the call to Stop() will block until all individual host queues are shut down.

Sending Emails

  1. Import Hectane's email package:

     import "github.com/hectane/hectane/email"
    
  2. Create an email.Email instance:

     e := &email.Email{
         From:    "[email protected]",
         To:      []string{"[email protected]"},
         Subject: "Test Email",
         Text:    "This is a test.",
     }
    
  3. Convert the email into queue.Message instances, using the queue's storage to write them to disk:

     msgs, err := e.Messages(q.Storage)
    
  4. Deliver the messages to the queue:

     for _, m := range msgs {
         q.Deliver(m)
     }
    
Clone this wiki locally