forked from socketlabs/socketlabs-go
/
BasicWithEmbeddedImage.go
34 lines (26 loc) · 1.09 KB
/
BasicWithEmbeddedImage.go
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 main
import (
"fmt"
"github.com/socketlabs/socketlabs-go/examples"
"github.com/socketlabs/socketlabs-go/injectionapi"
"github.com/socketlabs/socketlabs-go/injectionapi/message"
)
func main() {
client := injectionapi.CreateClient(exampleconfig.ServerId(), exampleconfig.APIKey())
basic := message.BasicMessage{}
basic.Subject = "Sending an Email With An Embedded Image"
basic.PlainTextBody = "Lorem Ipsum"
basic.From = message.EmailAddress{EmailAddress: "from@example.com"}
basic.AddToFriendlyEmailAddress("recipient@example.com", "Recipient")
//Add an image attachment
attachment, _ := message.NewAttachment("../../Img/bus.png")
attachment.ContentID = "bus" // specify the cid as 'Bus' so it can be embedded
basic.Attachments = append(basic.Attachments, attachment)
//Display the attachment in the html body
basic.HtmlBody = "<body><p><strong>Lorem Ipsum</strong></p><br /><img src=\"cid:Bus\" /></body>"
//Send the message
sendResponse, _ := client.SendBasic(&basic)
//Output the results
fmt.Println(sendResponse.Result.ToString())
fmt.Println(sendResponse.ResponseMessage)
}