Go SDK
Installation
- Using GitHub:The GitHub address for the Email & SMS SDK
For sending emails, import: import "github.com/sendcloud2013/sendcloud-sdk-go/email"
For sending SMS, import: import "github.com/sendcloud2013/sendcloud-sdk-go/sms"
For usage instructions, please refer to the README
- Manual Installation Download:Email & SMS SDK
How To Use
Create a SendCloud Client::
For Email:
client, err := sendcloud.NewSendCloud("API_KEY", "API_SECRET")
if err != nil {
// Handle the error, for example, by printing it or returning
log.Fatal(err)
}
For SMS:
client, err := sendcloud.NewSendCloudSms("SMS_USER", "SMS_KEY")
if err != nil {
// Handle the error, for example, by printing it or returning
log.Fatal(err)
}
Prepare Sending Parameters:: For Email:
args := &sendcloud.CommonMail{
Receiver: sendcloud.MailReceiver{
To: "a@ifaxin.com;b@ifaxin.com",
},
Body: sendcloud.MailBody{
From: "SendCloud@SendCloud.com",
Subject: "Email from SendCloud SDK",
FromName: "SendCloud",
},
Content: sendcloud.TextContent{
Html: "<p>This is an HTML email.</p>",
},
}
For SMS:
args := &sendcloud.SendSmsTemplateArgs{
TemplateId: 1, // Replace with the actual template ID
LabelId: 1, // Replace with the actual label ID (if applicable)
Phone: "13800138000", // Can be a single number or a comma-separated list of numbers
MsgType: sendcloud.SMS, // Assuming the sendcloud package defines an SMS constant
}
Invoke the Sending Method:: For Email:
result, err := client.SendCommonEmail(ctx, args)
if err != nil {
// Handle the error, for example, by printing it or returning
log.Fatal(err)
}
For SMS:
result, err := client.SendSmsTemplate(args)
if err != nil {
// Handle the error, for example, by printing it or returning
log.Fatal(err)
}