Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 2.25 KB

email.md

File metadata and controls

70 lines (51 loc) · 2.25 KB

Email API example

This example demonstrates how to use the Infobip Email API. You'll learn how to initialize an email client, send a message, and receive a delivery report.

The first step is to add your configuration, initialize the api client and set your authentication:

    configuration := infobip.NewConfiguration()
    configuration.Host = "<YOUR_BASE_URL>"
    
    infobipClient := api.NewAPIClient(configuration)
    
    auth := context.WithValue(
		context.Background(),
		infobip.ContextAPIKeys,
		map[string]infobip.APIKey{
			"APIKeyHeader": {Key: "<YOUR_API_KEY>", Prefix: "<YOUR_API_PREFIX>"},
		},
	)

For details, check the client source code.

Before sending an email message, you need to verify the domain with which you will be sending emails.

Send an Email with a file

Fields from, to, and subject are required. The message must also contain at least one of these: text, html, or templateId.


IMPORTANT NOTE

Keep in mind the following restrictions while using a trial account:

  • you can only send messages to verified email addresses,
  • you can only use your email address with the Infobip test domain in the following form: [email protected]

    apiResponse, httpResponse, err := infobipClient.
        EmailAPI.
        SendEmail(auth).
        To([]string{"[email protected]"}).
        From("Jane Smith <[email protected]>").
        Subject("Mail subject text").
        Text("Test message with a file")).
        Attachment([]*os.File{attachmentFile}).
        Execute()

Delivery reports

For each message that you send out, we can send you a delivery report in real time. All you need to do is specify your endpoint when sending email in the notifyUrl field.

Additionally, you can use a messageId or a bulkId autogenerated in a response for troubleshooting and to fetch reports.

    bulkId := "BULK-ID-123-xyz";
    numberOfReportsLimit := int32(10);

    response, _, err := infobipClient.
        EmailAPI.
        GetEmailDeliveryReports(auth).
        BulkId(bulkId).
        Limit(numberOfReportsLimit).
        Execute()