exchangelib

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 10 Imported by: 0

README

exchangelib-go

Go client for Microsoft Exchange Web Services (EWS)

Installation

Setting Up Go

To install Go, visit this link.

Installing Module

go get -u github.com/kangchengkun/exchangelib-go

Usage

Before using this Go module, you will need to fetch a access token from microsoft online by using https://github.com/kangchengkun/mso-token.

import github.com/kangchengkun/exchangelib-go

exchangelib.Sender = "your-mail-box"
exchangelib.AccessToken = "your-ews-token"

// Change the default exchange web service endpoint
exchangelib.ExchangeServerAddr = "your-exchange-server"


// Send an email
response, err := exchangelib.SendMail(to, cc, bcc, subject, body, attachments)
if err != nil {
    fmt.Println("SendMail failed")
}

Contribution

Follow the Guide to publish new versions

...
git add .
git commit -m "new updates"

$ git tag vx.x.x
$ git push origin vx.x.x

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Sender             string // mail or domain\account format
	AccessToken        string // the access token for exchange web services
	ExchangeServerAddr string = "https://outlook.office365.com/EWS/Exchange.asmx"
)

Functions

func BuildTextEmail

func BuildTextEmail(
	from string,
	to []string,
	cc []string,
	bcc []string,
	subject string,
	body []byte,
	attachments []FileAttachment,
) ([]byte, error)

func Issue

func Issue(ewsAddr string, body []byte) (*http.Response, error)

func SendMail

func SendMail(
	to []string,
	cc []string,
	bcc []string,
	topic string,
	content string,
	attachments []FileAttachment,
) (*http.Response, error)

Types

type Attachments

type Attachments struct {
	FileAttachment []FileAttachment `xml:"t:FileAttachment"`
}

type Body

type Body struct {
	BodyType string `xml:"BodyType,attr"` // https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/body#bodytype
	Body     []byte `xml:",chardata"`
}

type CreateItem

type CreateItem struct {
	XMLName            struct{}          `xml:"m:CreateItem"`
	MessageDisposition string            `xml:"MessageDisposition,attr"`
	SavedItemFolderId  SavedItemFolderId `xml:"m:SavedItemFolderId"`
	Items              Messages          `xml:"m:Items"`
}

type DistinguishedFolderId

type DistinguishedFolderId struct {
	Id string `xml:"Id,attr"`
}

type FileAttachment

type FileAttachment struct {
	Name             string    `xml:"t:Name"`
	ContentId        string    `xml:"t:ContentId"`
	ContentType      string    `xml:"t:ContentType"`     // default: "application/octet-stream"
	ContentLocation  string    `xml:"t:ContentLocation"` // the location of the content of an attachment
	Size             int32     `xml:"t:Size"`
	LastModifiedTime time.Time `xml:"t:LastModifiedTime"`
	IsInline         bool      `xml:"t:IsInline"`
	Content          string    `xml:"t:Content"`
}

ContentTypes refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types

type Mailbox

type Mailbox struct {
	EmailAddress string `xml:"t:EmailAddress"`
	RoutingType  string `xml:"t:RoutingType"`
	MailboxType  string `xml:"t:MailboxType"`
}

type Message

type Message struct {
	ItemClass                  string      `xml:"t:ItemClass"`
	Subject                    string      `xml:"t:Subject"`
	Body                       Body        `xml:"t:Body"`
	Attachments                Attachments `xml:"t:Attachments"`
	Sender                     OneMailbox  `xml:"t:Sender"`
	ToRecipients               XMailbox    `xml:"t:ToRecipients"`
	CcRecipients               XMailbox    `xml:"t:CcRecipients"`
	BccRecipients              XMailbox    `xml:"t:BccRecipients"`
	IsReadReceiptRequested     bool        `xml:"t:IsReadReceiptRequested"`     // whether a read receipt is requested for the e-mail message.
	IsDeliveryReceiptRequested bool        `xml:"t:IsDeliveryReceiptRequested"` // whether a delivery receipt is requested for the e-mail message.
}

type Messages

type Messages struct {
	Message []Message `xml:"t:Message"`
}

type OneMailbox

type OneMailbox struct {
	Mailbox Mailbox `xml:"t:Mailbox"`
}

type SavedItemFolderId

type SavedItemFolderId struct {
	DistinguishedFolderId DistinguishedFolderId `xml:"t:DistinguishedFolderId"`
}

type XMailbox

type XMailbox struct {
	Mailbox []Mailbox `xml:"t:Mailbox"`
}

Jump to

Keyboard shortcuts

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