Skip to content

Commit

Permalink
15.19.13 - add-unread-all
Browse files Browse the repository at this point in the history
  • Loading branch information
mailslurp-sdk-bot committed May 3, 2024
0 parents commit 5c40782
Show file tree
Hide file tree
Showing 660 changed files with 85,045 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
23 changes: 23 additions & 0 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
1 change: 1 addition & 0 deletions .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.3.1
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

install:
- go get -d -v .

script:
- go build -v ./

1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go.mailslurp.com
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 MailSlurp Email API (Provided by Pettman OÜ, Estonia)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
285 changes: 285 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
# Go Email API - Documentation

> Create and manage email addresses in GoLang. Send and receive emails and attachments in code and tests.
## Quick links

- [API documentation](https://docs.mailslurp.com/api/)
- [GitHub Repository](https://github.com/mailslurp/mailslurp-client-go/)
- [Full method documentation](https://go.mailslurp.com/)
- [Examples](https://www.mailslurp.com/examples/)
- [Guides](https://www.mailslurp.com/guides/)

### Common controllers

- [EmailController](https://go.mailslurp.com/#EmailControllerApiService) to send and receive emails
- [InboxController](https://go.mailslurp.com/#InboxControllerApiService) create email addresses
- [WaitForController](https://go.mailslurp.com/#WaitForControllerApiService) wait for emails to arrive

### Tutorial

- [Golang email library tutorial](https://www.mailslurp.com/examples/golang-email-testing/)

## Get started

MailSlurp is an email API that lets you create email addresses on demand then send and receive emails in code and tests. **No MailServer is required**.

This section describes how to get up and running with the Go client. To use another language or the REST API see the [developer page](https://www.mailslurp.com/developers/).

See the examples page for [code examples and use with common frameworks](https://www.mailslurp.com/examples/).

See the method documentation for a [list of all functions](https://github.com/mailslurp/mailslurp-client-go/).

## Get an API Key

You need a free MailSlurp account to use the service. [# for a free account](https://app.mailslurp.com/sign-up/) first.

## Install

```bash
go get github.com/mailslurp/mailslurp-client-go
```

You may also need these dependencies:

```bash
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional
```

MailSlurp's Go library uses `/antihax/optional` to wrap many parameters. Example usage looks like this:

```go
waitOpts := &mailslurp.WaitForLatestEmailOpts{
InboxId: optional.NewInterface(inbox2.Id),
Timeout: optional.NewInt64(30000),
UnreadOnly: optional.NewBool(true),
}
```

## Initialize

To initialize the MailSlurp client first [get an API Key](https://app.mailslurp.com). Then import the libraries:

```go
import (
"context"
"github.com/mailslurp/mailslurp-client-go"
)
```

Then configure the client:

```go
var apiKey = "your-mailslurp-client"

// create a context with your api key
ctx := context.WithValue(
context.Background(),
mailslurp.ContextAPIKey,
mailslurp.APIKey{ Key: apiKey }
)

// create mailslurp client
config := mailslurp.NewConfiguration()
client := mailslurp.NewAPIClient(config)
```

Controllers are then available on the client instance and can be passed your context and options:

```go
inbox, response, err := client.InboxControllerApi.CreateInbox(ctx, &mailslurp.CreateInboxOpts{})
```

## Example

```go
import (
"context"
"github.com/antihax/optional"
mailslurp "github.com/mailslurp/mailslurp-client-go"
"github.com/stretchr/testify/assert"
"os"
"testing"
"encoding/base64"
)

// create a client and a context
func createClient(t *testing.T) (*mailslurp.APIClient, context.Context) {
// read mailslurp api key from environment variable
var apiKey = os.Getenv("API_KEY")
assert.NotEmpty(t, apiKey, "API KEY is empty")

// create a context with your api key
ctx := context.WithValue(
context.Background(),
mailslurp.ContextAPIKey,
mailslurp.APIKey{Key: apiKey},
)

// create mailslurp client
config := mailslurp.NewConfiguration()
return mailslurp.NewAPIClient(config), ctx
}

func Test_CanCreateInbox(t *testing.T) {
client, ctx := createClient(t)

// call inbox controller to create an inbox
opts := &mailslurp.CreateInboxOpts{}
inbox, response, err := client.InboxControllerApi.CreateInbox(ctx, opts)

assert.Nil(t, err)
assert.Equal(t, response.StatusCode, 201)
assert.NotNil(t, inbox.Id)
assert.Contains(t, inbox.EmailAddress, "@mailslurp.com")
}
```

See the [Method Documentation](https://docs.mailslurp.com/go/) for more information or see the use cases below.

## Common use cases

Use controllers to manage MailSlurp entities.

### Create an inbox

Use the [InboxController](https://go.mailslurp.com/#InboxControllerApiService) to manage inboxes. You can create email addresses in MailSlurp by creating an inbox:

```go
opts := &mailslurp.CreateInboxOpts{}
inbox, response, err := client.InboxControllerApi.CreateInbox(ctx, opts)
```

The email address and ID are accessible on the Inbox:

```go
assert.NotNil(t, inbox.Id)
assert.Contains(t, inbox.EmailAddress, "@mailslurp.com")
```

#### Inbox types

Inboxes can be either `SMTP` or `HTTP` type. Set the inbox type using the `inboxType` property. SMTP inboxes are handled by a custom mailserver and support a wide range of clients while HTTP inboxes use Amazon SES and don't support some older clients like Outlook. SMTP inboxes are recommended for public facing email addresses while HTTP inboxes are best for application testing. Please see the guide on [types of inboxes](https://www.mailslurp.com/guides/smtp-vs-http-email-inboxes/) for more information.

### Send emails

To send emails first create an inbox then use the [SendEmailOptions](https://go.mailslurp.com/#SendEmailOptions) to configure the email.

```go
sendEmailOptions := mailslurp.SendEmailOptions{
To: []string{inbox.EmailAddress},
Subject: "Test email",
Body: "<h1>MailSlurp supports HTML</h1>",
IsHTML: true,
}
opts := &mailslurp.SendEmailOpts{
SendEmailOptions: optional.NewInterface(sendEmailOptions),
}
res, err := client.InboxControllerApi.SendEmail(ctx, inbox.Id, opts)
```

Here is another example:

```go
sendOpts := &mailslurp.SendEmailOpts{
SendEmailOptions: optional.NewInterface(mailslurp.SendEmailOptions{
To: []string{inbox2.EmailAddress},
Subject: "Test subject",
Body: "Hello from inbox 1",
Attachments: attachmentIds,
}),
}
```

### Receive emails

You can read emails in Go using the [WaitForControllerApi](https://go.mailslurp.com/#WaitForControllerApiService):

```go
// fetch the email for inbox2
waitOpts := &mailslurp.WaitForLatestEmailOpts{
InboxId: optional.NewInterface(inbox2.Id),
Timeout: optional.NewInt64(30000),
UnreadOnly: optional.NewBool(true),
}
email, response, err := client.WaitForControllerApi.WaitForLatestEmail(ctx, waitOpts)
```

You can extract the content of an email for use in your tests or application using regex and the email body:

```go
// can extract the contents
r := regexp.MustCompile(`Your code is: ([0-9]{3})`)
code := r.FindStringSubmatch(email.Body)[1]
```

## Attachments

Attachments can be sent by first uploading an attachment then using the returned ID with send email options. See the [AttachmentController](https://go.mailslurp.com/#AttachmentControllerApiService) to manage attachments.

```go
func uploadAttachment(t *testing.T) []string {
client, ctx := createClient(t)
attachmentBytes := []byte{0}
uploadOpts := mailslurp.UploadAttachmentOptions{
Base64Contents: base64.URLEncoding.EncodeToString(attachmentBytes),
ContentType: "text/plain",
Filename: "test.txt",
}
attachmentIds, _, err := client.AttachmentControllerApi.UploadAttachment(ctx, uploadOpts)
assert.Nil(t, err)
return attachmentIds
}

func Test_CanSendEmail_AndReceive(t *testing.T) {
client, ctx := createClient(t)
opts := &mailslurp.CreateInboxOpts{}

// create two inboxes
inbox1, _, err := client.InboxControllerApi.CreateInbox(ctx, opts)
inbox2, _, err := client.InboxControllerApi.CreateInbox(ctx, opts)

assert.Nil(t, err)

// upload attachments before send
attachmentIds := uploadAttachment(t)

// send a simple email from inbox 1 to inbox 2
sendOpts := &mailslurp.SendEmailOpts{
SendEmailOptions: optional.NewInterface(mailslurp.SendEmailOptions{
To: []string{inbox2.EmailAddress},
Subject: "Test subject",
Body: "Hello from inbox 1",
Attachments: attachmentIds,
}),
}

_, err = client.InboxControllerApi.SendEmail(ctx, inbox1.Id, sendOpts)
assert.Nil(t, err)

// now receive the email at inbox 2
waitForOpts := &mailslurp.WaitForLatestEmailOpts{
InboxId: optional.NewInterface(inbox2.Id),
Timeout: optional.NewInt64(30000),
UnreadOnly: optional.NewBool(true),
}
email, _, err := client.WaitForControllerApi.WaitForLatestEmail(ctx,waitForOpts)
assert.Nil(t, err)

// access content
assert.Equal(t, email.InboxId, inbox2.Id)
assert.Contains(t, email.Subject, "Test subject")
assert.Contains(t, email.Body, "Hello from inbox 1")

// download the attachment as bytes
downloadedBytes, _, err := client.EmailControllerApi.DownloadAttachment(ctx, email.Attachments[0], email.Id, nil)
assert.Nil(t, err)
assert.NotEmpty(t, downloadedBytes)
}
```

## Next step

For more information see the [source code on GitHub](https://github.com/mailslurp/mailslurp-client-go/) or documentation available at [MailSlurp's developer page](https://docs.mailslurp.com/).
4 changes: 4 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Security

This client calls the MailSlurp API endpoints. Connections should be made over secure HTTPS using your secure API Token. Do not share or commit the token if you can avoid doing so.
To report security issues or talk with MailSlurp support please email [contact@mailslurp.dev](mailto:contact@mailslurp.dev).
4 changes: 4 additions & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Support

To report issues or talk with MailSlurp support please email [contact@mailslurp.dev](mailto:contact@mailslurp.dev).
Alternatively you can visit our [support portal](https://www.mailslurp.com/support/) or open a ticket in the corresponding [Github repository](https://github.com/mailslurp).
Loading

0 comments on commit 5c40782

Please # to comment.