Last active
June 10, 2016 05:06
-
-
Save sym3tri/8a29ddecd65ec4f8ccfc to your computer and use it in GitHub Desktop.
easily email an attachment without reading from disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"bytes" | |
"io/ioutil" | |
"github.com/mailgun/mailgun-go" | |
) | |
func main() { | |
gun := mailgun.NewMailgun("valid-mailgun-domain", "private-mailgun-key", "public-mailgun-key") | |
// Create a new io.ReadCloser that reads an in-memory byte array buffer. | |
buf := &bytes.Buffer{} | |
buf.Write([]byte("these are the file contents")) | |
rc := ioutil.NopCloser(buf) | |
m := mailgun.NewMessage("from@example.com", "Subject", "message body", "to@example.com") | |
m.AddReaderAttachment("my-file.txt", rc) | |
response, id, _ := gun.Send(m) | |
fmt.Printf("Response ID: %s\n", id) | |
fmt.Printf("Message from server: %s\n", response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment