-
Notifications
You must be signed in to change notification settings - Fork 25
Hectane Package
Using Hectane in a Go application to send emails is extremely easy.
-
Import Hectane's
queue
package:import "github.com/hectane/hectane/queue"
-
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. -
Create a
queue.Queue
instance, passing thequeue.Config
from the previous step:q, err := queue.NewQueue(cfg)
-
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.
-
Import Hectane's
email
package:import "github.com/hectane/hectane/email"
-
Create an
email.Email
instance:e := &email.Email{ From: "me@example.com", To: []string{"you@example.com"}, Subject: "Test Email", Text: "This is a test.", }
-
Convert the email into
queue.Message
instances, using the queue's storage to write them to disk:msgs, err := e.Messages(q.Storage)
-
Deliver the messages to the queue:
for _, m := range msgs { q.Deliver(m) }