messagex

package module
v0.0.0-...-3f2192c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

MessageX SDK - Go


GoDoc Go Sourcegraph Go

MessageX Logo

https://www.gorillatoolkit.org/pkg/mux

MessageX SDK provides a library that provides an interface into the MessageX functionality.



Install Prerequisites

The following are the prerequisites for this package

Go v1.14

Use following page to install go https://golang.org/doc/install?download=go1.14.2.linux-amd64.tar.gz

Install

With a correctly configured Go toolchain:

go get -u github.com/messagex/go-messagex

Examples

Sending email

Import the library into your package

import (
    "github.com/messagex/go-messagex"
)

The following example shows how to send an email

package main

import (
   "bufio"
   "encoding/base64"
   "fmt"
   "io/ioutil"
   "os"

   "github.com/messagex/go-messagex"
)

var apiKey = "qsP8QCUF9q4Lmmv6dKDJukOIZ9vA1BVIRiy91RGjKaU42ovWtdYb2gwYaqhYY788"
var apiSecret = "ezEONICwdyMyPkLdU553wXz5xk0OoV4y6HnngRcAimj1hoid7ZLl61k9pV1bMDoY"

func main() {

   apiClient := messagex.CreateAPIClient(apiKey, apiSecret)

   err := apiClient.Login()
   if err != nil {
   	fmt.Printf("Error logging in to MessageX API: %s", err.Error())
   	os.Exit(0)
   }

   htmlBody :=  `
<!DOCTYPE HTML>
<html>
   <head>
       <meta charset="UTF-8">
       <title>Test Email Body</title>
   </head>
   <body>
       <h1>Test Email Body Heading</h1>
       <p>
           Test email body paragraph
       </p>
   </body>
</html>
`
   f, _ := os.Open("./image.png")

   // Read entire JPG into byte slice.
   reader := bufio.NewReader(f)
   content, _ := ioutil.ReadAll(reader)

   // Encode as base64.
   attPic := base64.StdEncoding.EncodeToString(content)
   
   email := apiClient.CreateEmail()
   email.SetFrom("Sender Name", "from@example.com")
   email.SetReplyTo("ReplyTo Name", "reply@example.com")
   email.AddTo("To Name", "to@example.com")
   email.AddCc("CC Name", "cc@example.com")
   email.AddBcc("BCC Name", "bcc@example.com")
   email.AddHeader("Content-Type", "application/json")
   email.SetSubject("Test email subject")
   email.SetHTMLBody(htmlBody)
   email.SetPlainBody("Example plain email body")
   email.AddAttachment("filename.jpg", "image/png", attPic)

   err = apiClient.SendEmail(email)
   if err != nil {
   	fmt.Printf("Error while sending an email to MessageX: %s", err.Error())
   	os.Exit(0)
   }
}

Developers

Installing GoDoc for Go v1.1.4

Once Go v1.14 has been installed, execute the following commands to install GoDoc from go-messagex project's root directory

GOBIN=`pwd`/bin && mkdir bin && go get -u golang.org/x/tools/cmd/godoc

Make sure you use the godoc tool that is installed in go-messagex/bin directory

Running documentation server

./dev-bin/docs

Navigate here to see the documentation:

http://localhost:6060/pkg/github.com/messagex/go-messagex

Note: Until the release to github, the address is http://localhost:6060/pkg/github.com/messagex/go-messagex/#APIClient

Note: We need to find out how to publish the documentation on godoc.org

Running Tests

To run unit tests execute the following command

./dev-bin/test

Documentation

Overview

Package MessageX provides the ADK to the MessageX API server

Copyright 2020 SMSGlobal. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	// contains filtered or unexported fields
}

func CreateAPIClient

func CreateAPIClient(user, pass string) *APIClient

CreateAPIClient - Initializes the MessageX api client library and provides a handle that can later be used to login to the MessageX API server and execute requests against it.

Parameters:

user - the login username/api key
pass - the password/api secret

Returns an instance of the APIClient

func (*APIClient) CreateEmail

func (c *APIClient) CreateEmail() *api.Email

CreateEmail - Creates an empty email object that is to be populated and sent to the MessageX API server

func (*APIClient) Login

func (c *APIClient) Login() error

Login - Logs the user in to the MessageX API server with the username and password provided in the call to CreateAPIClient.

Returns an error if it occurs

func (*APIClient) SendEmail

func (c *APIClient) SendEmail(msg *api.Email) error

SendEmail - Send the email to the MessageX API server

Parameters:

msg - An instance on the api.Email struct that represents the email message to be sent

Returns an error if it occurs

Directories

Path Synopsis
examples
interface
pkg
types
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL