Skip to content

Instantly share code, notes, and snippets.

@jittuu
Created November 16, 2023 07:54
Show Gist options
  • Save jittuu/b3623e65c92a9d9576484733bd0beab0 to your computer and use it in GitHub Desktop.
Save jittuu/b3623e65c92a9d9576484733bd0beab0 to your computer and use it in GitHub Desktop.
Send email using scaleway transactional emails
package main
import (
tem "github.com/scaleway/scaleway-sdk-go/api/tem/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/scw"
)
func main() {
// Read those from env
SCW_ACCESS_KEY := "SCW_ACCESS_KEY"
SCW_SECRET_KEY := "SCW_SECRET_KEY"
SCW_DEFAULT_ORGANIZATION_ID := "SCW_DEFAULT_ORGANIZATION_ID"
SCW_DEFAULT_PROJECT_ID := "SCW_DEFAULT_PROJECT_ID"
// Create a Scaleway client
client, err := scw.NewClient(
// Get your organization ID at https://console.scaleway.com/organization/settings
scw.WithDefaultOrganizationID(SCW_DEFAULT_ORGANIZATION_ID),
// Get your credentials at https://console.scaleway.com/iam/api-keys
scw.WithAuth(SCW_ACCESS_KEY, SCW_SECRET_KEY),
// Get more about our availability zones at https://www.scaleway.com/en/docs/console/my-account/reference-content/products-availability/
scw.WithDefaultRegion(scw.RegionFrPar),
scw.WithDefaultProjectID(SCW_DEFAULT_PROJECT_ID),
)
if err != nil {
panic(err)
}
temAPI := tem.NewAPI(client)
mail, err := temAPI.CreateEmail(&tem.CreateEmailRequest{
To: []*tem.CreateEmailRequestAddress{
{Email: "[email protected]"},
},
Subject: "Test Email",
HTML: `<div>
<p>(Shopper) Welcome back! Enter this code within the next 5 minutes to log in:</p>
<strong style="text-align: center">6379</strong>
</div>`,
From: &tem.CreateEmailRequestAddress{
Name: scw.StringPtr("Big Bee"),
Email: "[email protected]",
},
})
if err != nil {
panic(err)
}
// print all emails status
for _, email := range mail.Emails {
println(email.Status)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment