Skip to content

Commit

Permalink
Merge pull request #7 from evans-sudo/ListEmailTemplates
Browse files Browse the repository at this point in the history
ListEmailTemplates
  • Loading branch information
iqquee authored May 12, 2024
2 parents a48cd82 + 08c5a84 commit 55672e4
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
39 changes: 38 additions & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"
"os"
"path/filepath"

"github.com/iqquee/zeptomail"

)

func main() {
Expand Down Expand Up @@ -36,6 +38,10 @@ func main() {

// FileCacheUploadAPI is used to upload a file to the cache.
FileCacheUploadAPI()

//GetEmailTemplates is used to list the required number of email templates in your ZeptoMail account.
ListEmailTemplates()

}

// sendHTMLEmail sends a HTML Email
Expand Down Expand Up @@ -300,10 +306,41 @@ func SendBatchHTMLEmail() {

for _, e := range res.Data {
fmt.Printf("response message: %v\n", e.Message)
}



}



func ListEmailTemplates() {

zeptomailToken := "your zeptomail authorization token"

client := zeptomail.New(*http.DefaultClient, zeptomailToken)

var Offset, Limit int;
var MailagentAlias string;


res, err := client.ListEmailTemplates(MailagentAlias, Offset, Limit)
if err != nil {
fmt.Printf("This is the error: %v", err.Error())
}

fmt.Printf("response message: %v\n", res.Message)
}









}




Expand Down
20 changes: 20 additions & 0 deletions mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,23 @@ func (c *Client) FileCacheUploadAPI(req FileCacheUploadAPIReq) (res *FileCacheUp
return &response, nil

}
ListEmailTemplates


func (c *Client) ListEmailTemplates(MailAgentAlias string, Offset, limit int) (req *ListEmailTemplatesReq, err error) {
url := fmt.Sprintf("mailagents/%s/templates?offset=%d&limit=%d", MailAgentAlias, Offset, limit)
Method := MethodGET

if err := validate.Struct(&req); err != nil {
return nil, err
}

var response ListEmailTemplatesReq

if err := c.newRequest(url, Method, nil, response); err != nil {
return nil, err
}

return &response, nil
}

7 changes: 7 additions & 0 deletions mail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package zeptomail

import "testing"

func TestGetEmailTemplates(t *testing.T) {

}
25 changes: 25 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,29 @@ type (
AdditionalInfo []interface{} `json:"additional_info"`
Message string `json:"message"`
}

// Template Request is the ListEmailTemplates() request object
ListEmailTemplatesReq struct {

metadata struct {
MailAgentAlias string `json: "mailagentalias"`
Offset int `json: "offset"`
Limit int `json: "limit"`
}

data struct {
CreatedTime string `json: "createdtime"`
TemplateName string `json: "templatename"`
TemplateKey string `json: "templatekey"`
ModifiedTime string `json: modifiedtime"`
Subject string `"json: subject"`
TemplateAlias string `"json: templatealias"`
}`json:"data"`

Message string `json:"message"`

}



)

0 comments on commit 55672e4

Please sign in to comment.