A small library to send physical mail from your Go applications using https://mailform.io
First you will need an API Token from mailform.io
go get github.com/circa10a/go-mailform
package main
import (
"fmt"
"os"
"github.com/circa10a/go-mailform"
)
func main() {
client, err := mailform.New(&mailform.Config{
Token: "MAILFORM_API_TOKEN",
})
if err != nil {
fmt.Println(err)
}
// Create order
// You can send a PDF file via local filesystem path or a URL.
// FilePath will take precedence over URL.
order, err := client.CreateOrder(mailform.OrderInput{
// Send local pdf
FilePath: "./sample.pdf",
// Or you can send the file via URL
URL: "http://s3.amazonaws.com/some-bucket/sample.pdf",
// Shipping service options:
// FEDEX_OVERNIGHT USPS_PRIORITY_EXPRESS USPS_PRIORITY USPS_CERTIFIED_PHYSICAL_RECEIPT USPS_CERTIFIED_RECEIPT USPS_CERTIFIED USPS_FIRST_CLASS USPS_STANDARD USPS_POSTCARD
Service: "USPS_PRIORITY",
ToName: "A Name",
ToAddress1: "Address 1",
ToCity: "Seattle",
ToState: "WA",
ToPostcode: "00000",
ToCountry: "US",
FromName: "My Name",
FromAddress1: "My Address 1",
FromCity: "Dallas",
FromState: "TX",
FromPostcode: "00000",
FromCountry: "US",
})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Order ID", order.Data.ID)
// Get Order
orderDetails, err := client.GetOrder(order.Data.ID)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(orderDetails.Data)
}