-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_incoming_test.go
More file actions
34 lines (28 loc) · 968 Bytes
/
example_incoming_test.go
File metadata and controls
34 lines (28 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package cloudmailin_test
import (
"fmt"
"log"
"net/http"
"github.com/cloudmailin/cloudmailin-go"
)
func handleIncomingPOST(w http.ResponseWriter, req *http.Request) {
// Parse the message from the request body
message, err := cloudmailin.ParseIncoming(req.Body)
if err != nil {
// Print an error message if parsing fails
fmt.Fprint(w, "Error parsing message: ", err)
}
// Output the first instance of the message-id in the headers to show
// that we correctly parsed the message. We could also use the helper
// message.Headers.MessageID().
fmt.Fprint(w, "Thanks for message: ", message.Headers.First("message_id"))
}
// This example shows how to parse the incoming JSON sent by Cloudmailin
// and create an instance of the IncomingMail type.
func ExampleParseIncoming() {
http.HandleFunc("/", handleIncomingPOST)
// Start the HTTP server to listen for HTTP POST
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}