forked from temp-mail-io/temp-mail-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_email_messages.go
More file actions
62 lines (55 loc) · 2 KB
/
Copy pathlist_email_messages.go
File metadata and controls
62 lines (55 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package tempmail
import (
"context"
"fmt"
"net/http"
"time"
)
// ListEmailMessagesResponse represents the response to list email messages.
type ListEmailMessagesResponse struct {
Messages []ListEmailMessagesMessageResponse `json:"messages"`
}
// ListEmailMessagesMessageResponse represents an email message.
type ListEmailMessagesMessageResponse struct {
// ID is the unique identifier of the email message.
ID string `json:"id"`
// From is the email address of the sender.
From string `json:"from"`
// To is the email address of the recipient.
To string `json:"to"`
// CC is the email addresses of the CC recipients.
CC []string `json:"cc"`
// Subject is the subject of the email message.
Subject string `json:"subject"`
// BodyText is the plain text body of the email message.
BodyText string `json:"body_text"`
// BodyHTML is the HTML body of the email message.
BodyHTML string `json:"body_html"`
// CreatedAt is the time when the email message was created.
CreatedAt time.Time `json:"created_at"`
// Attachments is the list of attachments of the email message.
Attachments []ListEmailMessagesAttachmentResponse `json:"attachments"`
}
// ListEmailMessagesAttachmentResponse represents an attachment of an email message.
type ListEmailMessagesAttachmentResponse struct {
// ID is the unique identifier of the attachment.
ID string `json:"id"`
// Name is the name of the attachment.
// For example, "image.png".
Name string `json:"name"`
// Size is the size of the attachment in bytes.
Size int `json:"size"`
}
// ListEmailMessages returns all messages for the email address.
func (c *Client) ListEmailMessages(ctx context.Context, email string) (ListEmailMessagesResponse, *Response, error) {
req, err := c.newRequest(ctx, http.MethodGet, fmt.Sprintf("/v1/emails/%s/messages", email), nil)
if err != nil {
return ListEmailMessagesResponse{}, nil, err
}
var resp ListEmailMessagesResponse
r, err := c.do(req, &resp)
if err != nil {
return ListEmailMessagesResponse{}, nil, err
}
return resp, r, nil
}