├── .github
└── workflows
│ ├── build.yml
│ └── publish.yml
├── .gitignore
├── .project
├── LICENSE
├── README.md
├── mailosaur-java.iml
├── pom.xml
├── pom.xml.versionsBackup
└── src
├── main
├── java
│ └── com
│ │ └── mailosaur
│ │ ├── Analysis.java
│ │ ├── Devices.java
│ │ ├── Files.java
│ │ ├── MailosaurClient.java
│ │ ├── MailosaurException.java
│ │ ├── Messages.java
│ │ ├── Previews.java
│ │ ├── Servers.java
│ │ ├── Usage.java
│ │ ├── models
│ │ ├── Attachment.java
│ │ ├── BaseModel.java
│ │ ├── BlockListResult.java
│ │ ├── Code.java
│ │ ├── Content.java
│ │ ├── DeliverabilityReport.java
│ │ ├── Device.java
│ │ ├── DeviceCreateOptions.java
│ │ ├── DeviceListResult.java
│ │ ├── DnsRecords.java
│ │ ├── EmailAuthenticationResult.java
│ │ ├── Image.java
│ │ ├── Link.java
│ │ ├── Message.java
│ │ ├── MessageAddress.java
│ │ ├── MessageContent.java
│ │ ├── MessageCreateOptions.java
│ │ ├── MessageForwardOptions.java
│ │ ├── MessageHeader.java
│ │ ├── MessageListParams.java
│ │ ├── MessageListResult.java
│ │ ├── MessageReplyOptions.java
│ │ ├── MessageSearchParams.java
│ │ ├── MessageSummary.java
│ │ ├── Metadata.java
│ │ ├── OtpResult.java
│ │ ├── Preview.java
│ │ ├── PreviewEmailClient.java
│ │ ├── PreviewEmailClientListResult.java
│ │ ├── PreviewListResult.java
│ │ ├── PreviewRequest.java
│ │ ├── PreviewRequestOptions.java
│ │ ├── SearchCriteria.java
│ │ ├── SearchMatchOperator.java
│ │ ├── Server.java
│ │ ├── ServerCreateOptions.java
│ │ ├── ServerListResult.java
│ │ ├── SpamAnalysisResult.java
│ │ ├── SpamAssassinResult.java
│ │ ├── SpamAssassinRule.java
│ │ ├── SpamFilterResults.java
│ │ ├── UsageAccountLimit.java
│ │ ├── UsageAccountLimits.java
│ │ ├── UsageTransaction.java
│ │ ├── UsageTransactionListResult.java
│ │ └── package-info.java
│ │ └── package-info.java
└── main.iml
└── test
├── java
└── com
│ └── mailosaur
│ ├── DevicesTest.java
│ ├── EmailsTest.java
│ ├── ErrorsTest.java
│ ├── FilesTest.java
│ ├── Mailer.java
│ ├── PreviewsTest.java
│ ├── ServersTest.java
│ └── UsageTest.java
├── resources
├── cat.png
├── dog.png
├── testEmail.html
└── testEmail.txt
└── test.iml
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: CI
5 |
6 | on:
7 | push:
8 | branches: [main]
9 | pull_request:
10 | branches: [main]
11 | workflow_dispatch:
12 |
13 | concurrency:
14 | group: mailosaur-java
15 | cancel-in-progress: true
16 |
17 | jobs:
18 | build:
19 | runs-on: ${{ vars.LINUX }}
20 | timeout-minutes: 10
21 |
22 | env:
23 | MAILOSAUR_BASE_URL: https://mailosaur.com/
24 | MAILOSAUR_SMTP_HOST: mailosaur.net
25 | MAILOSAUR_SMTP_PORT: 2525
26 | MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}
27 | MAILOSAUR_SERVER: ${{ secrets.MAILOSAUR_SERVER }}
28 | MAILOSAUR_VERIFIED_DOMAIN: ${{ secrets.MAILOSAUR_VERIFIED_DOMAIN }}
29 | MAILOSAUR_PREVIEWS_SERVER: ${{ secrets.MAILOSAUR_PREVIEWS_SERVER }}
30 |
31 | steps:
32 | - uses: actions/checkout@v2
33 | - name: Setup Java
34 | uses: actions/setup-java@v4
35 | with:
36 | java-version: ${{ vars.JAVA_VERSION }}
37 | distribution: jetbrains
38 | - name: Build with Maven
39 | run: mvn -B package --file pom.xml
40 | - name: Notify on Failure
41 | uses: skitionek/notify-microsoft-teams@master
42 | if: ${{ failure() }}
43 | with:
44 | webhook_url: ${{ secrets.TEAMS_BUILDS_WEBHOOK }}
45 | needs: ${{ toJson(needs) }}
46 | job: ${{ toJson(job) }}
47 | overwrite: "{ title: `${workflow} failed for ${repository.name}` }"
48 |
49 | build-next:
50 | if: ${{ always() }}
51 | needs: build
52 | runs-on: ${{ vars.LINUX }}
53 | timeout-minutes: 10
54 |
55 | env:
56 | MAILOSAUR_BASE_URL: https://next.mailosaur.com/
57 | MAILOSAUR_SMTP_HOST: mailosaur.email
58 | MAILOSAUR_SMTP_PORT: 2525
59 | MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}
60 | MAILOSAUR_SERVER: ${{ secrets.MAILOSAUR_SERVER }}
61 | MAILOSAUR_VERIFIED_DOMAIN: ${{ secrets.MAILOSAUR_VERIFIED_DOMAIN }}
62 | MAILOSAUR_PREVIEWS_SERVER: ${{ secrets.MAILOSAUR_PREVIEWS_SERVER }}
63 |
64 | steps:
65 | - uses: actions/checkout@v2
66 | - name: Set up JDK 1.8
67 | uses: actions/setup-java@v4
68 | with:
69 | java-version: ${{ vars.JAVA_VERSION }}
70 | distribution: temurin
71 | - name: Build with Maven
72 | run: mvn -B package --file pom.xml
73 | - name: Notify on Failure
74 | uses: skitionek/notify-microsoft-teams@master
75 | if: ${{ failure() }}
76 | with:
77 | webhook_url: ${{ secrets.TEAMS_BUILDS_WEBHOOK }}
78 | needs: ${{ toJson(needs) }}
79 | job: ${{ toJson(job) }}
80 | overwrite: "{ title: `${workflow} failed for ${repository.name}` }"
81 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | release:
5 | types: [created]
6 |
7 | jobs:
8 | publish:
9 | runs-on: ${{ vars.LINUX }}
10 | timeout-minutes: 10
11 |
12 | env:
13 | MAILOSAUR_BASE_URL: https://mailosaur.com/
14 | MAILOSAUR_SMTP_HOST: mailosaur.net
15 | MAILOSAUR_SMTP_PORT: 2525
16 | MAILOSAUR_API_KEY: ${{ secrets.MAILOSAUR_API_KEY }}
17 | MAILOSAUR_SERVER: ${{ secrets.MAILOSAUR_SERVER }}
18 | MAILOSAUR_VERIFIED_DOMAIN: ${{ secrets.MAILOSAUR_VERIFIED_DOMAIN }}
19 | MAILOSAUR_PREVIEWS_SERVER: ${{ secrets.MAILOSAUR_PREVIEWS_SERVER }}
20 |
21 | steps:
22 | - uses: actions/checkout@v2
23 | - name: Setup Java
24 | uses: actions/setup-java@v4
25 | with:
26 | java-version: ${{ vars.JAVA_VERSION }}
27 | distribution: jetbrains
28 | server-id: central
29 | server-username: MAVEN_USERNAME
30 | server-password: MAVEN_PASSWORD
31 | gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
32 | gpg-passphrase: MAVEN_GPG_PASSPHRASE
33 | - name: Version
34 | run: |
35 | version=`git describe --abbrev=0 --tags` &&
36 | sed -i s/\[0-9]\.\[0-9]\.\[0-9]/$version/ src/main/java/com/mailosaur/MailosaurClient.java &&
37 | mvn versions:set -DnewVersion=$version
38 | - name: Publish
39 | run: |
40 | mvn deploy
41 | env:
42 | MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
43 | MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
44 | MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
45 | - name: Notify on Failure
46 | uses: skitionek/notify-microsoft-teams@master
47 | if: ${{ failure() }}
48 | with:
49 | webhook_url: ${{ secrets.TEAMS_BUILDS_WEBHOOK }}
50 | needs: ${{ toJson(needs) }}
51 | job: ${{ toJson(job) }}
52 | overwrite: "{ title: `${workflow} failed for ${repository.name}` }"
53 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 | .settings
3 | .classpath
4 | *.iml
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 | /target
11 | *.DS_Store
12 | release.properties
13 | /.idea/
14 | /.project
15 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
codes;
21 |
22 | /**
23 | * Any images found within this content.
24 | */
25 | @Key
26 | private List images;
27 |
28 | /**
29 | * The HTML or plain text body of the message.
30 | */
31 | @Key
32 | private String body;
33 |
34 | /**
35 | * Gets any hyperlinks found within this content.
36 | *
37 | * @return Any hyperlinks found within this content.
38 | */
39 | public List links() {
40 | return this.links;
41 | }
42 |
43 | /**
44 | * Gets any verification codes found within this content.
45 | *
46 | * @return Any verification codes found within this content.
47 | */
48 | public List codes() {
49 | return this.codes;
50 | }
51 |
52 | /**
53 | * Gets any images found within this content.
54 | *
55 | * @return Any images found within this content.
56 | */
57 | public List images() {
58 | return this.images;
59 | }
60 |
61 | /**
62 | * Gets the HTML or plain text body of the message.
63 | *
64 | * @return The HTML or plain text body of the message.
65 | */
66 | public String body() {
67 | return nullableString(this.body);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageCreateOptions.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Options to use when creating a new message.
9 | */
10 | public class MessageCreateOptions {
11 | /**
12 | * The email address to which the email will be sent. Must be a verified email address.
13 | */
14 | @Key
15 | private String to;
16 |
17 | /**
18 | * The email address to which the email will be CC'd. Must be a verified email address.
19 | */
20 | @Key
21 | private String cc;
22 |
23 | /**
24 | * Allows for the partial override of the message's 'from' address. This **must** be
25 | * an address ending with `YOUR_SERVER.mailosaur.net`, such as `my-emails@a1bcdef2.mailosaur.net`.
26 | */
27 | @Key
28 | private String from;
29 |
30 | /**
31 | * If true, email will be sent upon creation.
32 | */
33 | @Key
34 | private Boolean send;
35 |
36 | /**
37 | * The email subject line.
38 | */
39 | @Key
40 | private String subject;
41 |
42 | /**
43 | * The plain text body of the message. Note that only text or html can be supplied, not both.
44 | */
45 | @Key
46 | private String text;
47 |
48 | /**
49 | * The HTML body of the message. Note that only text or html can be supplied, not both.
50 | */
51 | @Key
52 | private String html;
53 |
54 | /**
55 | * Any message attachments.
56 | */
57 | @Key
58 | private List attachments;
59 |
60 | /**
61 | * Sets the email address to which the email will be sent. Must be a verified email address.
62 | *
63 | * @param to The email address.
64 | * @return the MessageCreateOptions object itself.
65 | */
66 | public MessageCreateOptions withTo(String to) {
67 | this.to = to;
68 | return this;
69 | }
70 |
71 | /**
72 | * Sets the email address to which the email will be CC'd. Must be a verified email address.
73 | *
74 | * @param cc The email address.
75 | * @return the MessageCreateOptions object itself.
76 | */
77 | public MessageCreateOptions withCc(String cc) {
78 | this.cc = cc;
79 | return this;
80 | }
81 |
82 | /**
83 | * Partially overrides of the message's 'from' address. This **must** be an address ending
84 | * with `YOUR_SERVER.mailosaur.net`, such as `my-emails@a1bcdef2.mailosaur.net`.
85 | *
86 | * @param from The email address.
87 | * @return the MessageCreateOptions object itself.
88 | */
89 | public MessageCreateOptions withFrom(String from) {
90 | this.from = from;
91 | return this;
92 | }
93 |
94 | /**
95 | * Sets whether the email should be sent upon creation.
96 | *
97 | * @param send If true, email will be sent upon creation.
98 | * @return the MessageCreateOptions object itself.
99 | */
100 | public MessageCreateOptions withSend(Boolean send) {
101 | this.send = send;
102 | return this;
103 | }
104 |
105 | /**
106 | * Sets the email subject line.
107 | *
108 | * @param subject The email subject line.
109 | * @return the MessageCreateOptions object itself.
110 | */
111 | public MessageCreateOptions withSubject(String subject) {
112 | this.subject = subject;
113 | return this;
114 | }
115 |
116 | /**
117 | * Sets any plain text to include when forwarding the message. Note that only text or html can be supplied, not both.
118 | *
119 | * @param text Plain text content to include when forwarding the message.
120 | * @return the MessageCreateOptions object itself.
121 | */
122 | public MessageCreateOptions withText(String text) {
123 | this.text = text;
124 | return this;
125 | }
126 |
127 | /**
128 | * Sets any HTML content to include when forwarding the message. Note that only text or html can be supplied, not both.
129 | *
130 | * @param html HTML content to include when forwarding the message.
131 | * @return the MessageCreateOptions object itself.
132 | */
133 | public MessageCreateOptions withHtml(String html) {
134 | this.html = html;
135 | return this;
136 | }
137 |
138 | /**
139 | * Sets any message attachments.
140 | *
141 | * @param attachments Any message attachments.
142 | * @return the MessageCreateOptions object itself.
143 | */
144 | public MessageCreateOptions withAttachments(List attachments) {
145 | this.attachments = attachments;
146 | return this;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageForwardOptions.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Options to use when forwarding a message.
7 | */
8 | public class MessageForwardOptions {
9 | /**
10 | * The email address to which the email will be sent. Must be a verified email address.
11 | */
12 | @Key
13 | private String to;
14 |
15 | /**
16 | * The email address to which the email will be CC'd. Must be a verified email address.
17 | */
18 | @Key
19 | private String cc;
20 |
21 | /**
22 | * Any plain text to include when forwarding the message. Note that only text or html can be supplied, not both.
23 | */
24 | @Key
25 | private String text;
26 |
27 | /**
28 | * Any HTML content to include when forwarding the message. Note that only text or html can be supplied, not both.
29 | */
30 | @Key
31 | private String html;
32 |
33 | /**
34 | * Sets the email address to which the email will be sent. Must be a verified email address.
35 | *
36 | * @param to The email address.
37 | * @return the MessageForwardOptions object itself.
38 | */
39 | public MessageForwardOptions withTo(String to) {
40 | this.to = to;
41 | return this;
42 | }
43 |
44 | /**
45 | * Sets the email address to which the email will be CC'd. Must be a verified email address.
46 | *
47 | * @param cc The email address.
48 | * @return the MessageCreateOptions object itself.
49 | */
50 | public MessageForwardOptions withCc(String cc) {
51 | this.cc = cc;
52 | return this;
53 | }
54 |
55 | /**
56 | * Sets any plain text to include when forwarding the message. Note that only text or html can be supplied, not both.
57 | *
58 | * @param text Plain text content to include when forwarding the message.
59 | * @return the MessageForwardOptions object itself.
60 | */
61 | public MessageForwardOptions withText(String text) {
62 | this.text = text;
63 | return this;
64 | }
65 |
66 | /**
67 | * Sets any HTML content to include when forwarding the message. Note that only text or html can be supplied, not both.
68 | *
69 | * @param html HTML content to include when forwarding the message.
70 | * @return the MessageForwardOptions object itself.
71 | */
72 | public MessageForwardOptions withHtml(String html) {
73 | this.html = html;
74 | return this;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageHeader.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Message header key/value pair.
7 | */
8 | public class MessageHeader extends BaseModel {
9 | /**
10 | * Header key.
11 | */
12 | @Key
13 | private String field;
14 |
15 | /**
16 | * Header value.
17 | */
18 | @Key
19 | private String value;
20 |
21 | /**
22 | * Gets the header key.
23 | *
24 | * @return The header key.
25 | */
26 | public String field() {
27 | return nullableString(this.field);
28 | }
29 |
30 | /**
31 | * Gets the header value.
32 | *
33 | * @return The header value.
34 | */
35 | public String value() {
36 | return nullableString(this.value);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageListParams.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Parameters for message listing.
7 | */
8 | public class MessageListParams {
9 | /**
10 | * The identifier of the server hosting the messages.
11 | */
12 | @Key
13 | private String server;
14 |
15 | /**
16 | * Limits results to only messages received after this timestamp.
17 | */
18 | @Key
19 | private Long receivedAfter;
20 |
21 | /**
22 | * Used in conjunction with `itemsPerPage` to support pagination.
23 | */
24 | @Key
25 | private Integer page;
26 |
27 | /**
28 | * A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
29 | */
30 | @Key
31 | private Integer itemsPerPage;
32 |
33 | /**
34 | * Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
35 | */
36 | @Key
37 | private String dir;
38 |
39 | /**
40 | * Gets the identifier of the server hosting the messages.
41 | *
42 | * @return The identifier of the server hosting the messages.
43 | */
44 | public String server() {
45 | return this.server;
46 | }
47 |
48 | /**
49 | * Gets the receivedAfter timestamp.
50 | *
51 | * @return The receivedAfter timestamp.
52 | */
53 | public Long receivedAfter() {
54 | return this.receivedAfter;
55 | }
56 |
57 | /**
58 | * Gets the page index, used in conjunction with `itemsPerPage` to support pagination.
59 | *
60 | * @return Gets the page index (for pagination).
61 | */
62 | public Integer page() {
63 | return this.page;
64 | }
65 |
66 | /**
67 | * Gets the limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
68 | *
69 | * @return The number of results to be returned per page.
70 | */
71 | public Integer itemsPerPage() {
72 | return this.itemsPerPage;
73 | }
74 |
75 | /**
76 | * Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
77 | *
78 | * @return Either `Sent` or `Received`.
79 | */
80 | public String dir() {
81 | return this.dir;
82 | }
83 |
84 | /**
85 | * Sets the identifier of the server hosting the messages.
86 | *
87 | * @param server The identifier of the server hosting the messages.
88 | * @return the MessageSearchParams object itself.
89 | */
90 | public MessageListParams withServer(String server) {
91 | this.server = server;
92 | return this;
93 | }
94 |
95 | /**
96 | * Limits results to only messages received after this timestamp.
97 | *
98 | * @param receivedAfter Limits results to only messages received after this timestamp.
99 | * @return the MessageSearchParams object itself.
100 | */
101 | public MessageListParams withReceivedAfter(long receivedAfter) {
102 | this.receivedAfter = receivedAfter;
103 | return this;
104 | }
105 |
106 | /**
107 | * Sets the page index, used in conjunction with `itemsPerPage` to support pagination.
108 | *
109 | * @param page Used in conjunction with `itemsPerPage` to support pagination.
110 | * @return the MessageSearchParams object itself.
111 | */
112 | public MessageListParams withPage(int page) {
113 | this.page = page;
114 | return this;
115 | }
116 |
117 | /**
118 | * Set the limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
119 | *
120 | * @param itemsPerPage A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
121 | * @return the MessageSearchParams object itself.
122 | */
123 | public MessageListParams withItemsPerPage(int itemsPerPage) {
124 | this.itemsPerPage = itemsPerPage;
125 | return this;
126 | }
127 |
128 | /**
129 | * Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
130 | *
131 | * @param dir Can be either `Sent` or `Received`, with the default being `Received`.
132 | * @return the MessageSearchParams object itself.
133 | */
134 | public MessageListParams withDir(String dir) {
135 | this.dir = dir;
136 | return this;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageListResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | * The result of a message listing request.
8 | */
9 | public class MessageListResult {
10 | /**
11 | * The individual summaries of each message forming the
12 | * result. Summaries are returned sorted by received date, with the most
13 | * recently-received messages appearing first.
14 | */
15 | @Key
16 | private List items;
17 |
18 | /**
19 | * Gets the individual summaries of each message forming the
20 | * result. Summaries are returned sorted by received date, with the most
21 | * recently-received messages appearing first.
22 | *
23 | * @return The individual summaries of each message forming the result.
24 | */
25 | public List items() {
26 | return this.items;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageReplyOptions.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Options to use when replying to a message.
9 | */
10 | public class MessageReplyOptions {
11 | /**
12 | * Any additional plain text content to include in the reply. Note that only text or html can be supplied, not both.
13 | */
14 | @Key
15 | private String text;
16 |
17 | /**
18 | * Any additional HTML content to include in the reply. Note that only html or text can be supplied, not both.
19 | */
20 | @Key
21 | private String html;
22 |
23 | /**
24 | * The email address to which the email will be CC'd. Must be a verified email address.
25 | */
26 | @Key
27 | private String cc;
28 |
29 | /**
30 | * Any message attachments.
31 | */
32 | @Key
33 | private List attachments;
34 |
35 | /**
36 | * Sets any additional plain text content to include in the reply. Note that only text or html can be supplied, not both.
37 | *
38 | * @param text Plain text content to include in the reply.
39 | * @return the MessageReplyOptions object itself.
40 | */
41 | public MessageReplyOptions withText(String text) {
42 | this.text = text;
43 | return this;
44 | }
45 |
46 | /**
47 | * Sets any additional HTML content to include in the reply. Note that only html or text can be supplied, not both.
48 | *
49 | * @param html HTML content to include in the reply.
50 | * @return the MessageReplyOptions object itself.
51 | */
52 | public MessageReplyOptions withHtml(String html) {
53 | this.html = html;
54 | return this;
55 | }
56 |
57 | /**
58 | * Sets the email address to which the email will be CC'd. Must be a verified email address.
59 | *
60 | * @param cc The email address.
61 | * @return the MessageCreateOptions object itself.
62 | */
63 | public MessageReplyOptions withCc(String cc) {
64 | this.cc = cc;
65 | return this;
66 | }
67 |
68 | /**
69 | * Sets any message attachments.
70 | *
71 | * @param attachments Any message attachments.
72 | * @return the MessageReplyOptions object itself.
73 | */
74 | public MessageReplyOptions withAttachments(List attachments) {
75 | this.attachments = attachments;
76 | return this;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageSearchParams.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Parameters for message searching.
7 | */
8 | public class MessageSearchParams {
9 | /**
10 | * The identifier of the server hosting the messages.
11 | */
12 | @Key
13 | private String server;
14 |
15 | /**
16 | * Limits results to only messages received after this timestamp.
17 | */
18 | @Key
19 | private Long receivedAfter;
20 |
21 | /**
22 | * Used in conjunction with `itemsPerPage` to support pagination.
23 | */
24 | @Key
25 | private Integer page;
26 |
27 | /**
28 | * A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
29 | */
30 | @Key
31 | private Integer itemsPerPage;
32 |
33 | /**
34 | * Specify how long to wait for a matching result (in milliseconds).
35 | */
36 | @Key
37 | private Integer timeout;
38 |
39 | /**
40 | * When set to false, an error will not be throw if timeout is reached (default: true).
41 | */
42 | @Key
43 | private Boolean errorOnTimeout;
44 |
45 | /**
46 | * Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
47 | */
48 | @Key
49 | private String dir;
50 |
51 | /**
52 | * Gets the identifier of the server hosting the messages.
53 | *
54 | * @return The identifier of the server hosting the messages.
55 | */
56 | public String server() {
57 | return this.server;
58 | }
59 |
60 | /**
61 | * Gets the receivedAfter timestamp.
62 | *
63 | * @return The receivedAfter timestamp.
64 | */
65 | public Long receivedAfter() {
66 | return this.receivedAfter;
67 | }
68 |
69 | /**
70 | * Gets the page index, used in conjunction with `itemsPerPage` to support pagination.
71 | *
72 | * @return Gets the page index (for pagination).
73 | */
74 | public Integer page() {
75 | return this.page;
76 | }
77 |
78 | /**
79 | * Gets the limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
80 | *
81 | * @return The number of results to be returned per page.
82 | */
83 | public Integer itemsPerPage() {
84 | return this.itemsPerPage;
85 | }
86 |
87 | /**
88 | * Gets how long to wait for a matching result (in milliseconds).
89 | *
90 | * @return The time to wait for a matching result (in milliseconds).
91 | */
92 | public Integer timeout() {
93 | return this.timeout;
94 | }
95 |
96 | /**
97 | * Gets whether or not an error will not be throw if timeout is reached (default: true).
98 | *
99 | * @return Whether or not an error will not be throw if timeout is reached (default: true).
100 | */
101 | public Boolean errorOnTimeout() {
102 | return this.errorOnTimeout;
103 | }
104 |
105 | /**
106 | * Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
107 | *
108 | * @return Either `Sent` or `Received`.
109 | */
110 | public String dir() {
111 | return this.dir;
112 | }
113 |
114 | /**
115 | * Sets the identifier of the server hosting the messages.
116 | *
117 | * @param server The identifier of the server hosting the messages.
118 | * @return the MessageSearchParams object itself.
119 | */
120 | public MessageSearchParams withServer(String server) {
121 | this.server = server;
122 | return this;
123 | }
124 |
125 | /**
126 | * Limits results to only messages received after this timestamp.
127 | *
128 | * @param receivedAfter Limits results to only messages received after this timestamp.
129 | * @return the MessageSearchParams object itself.
130 | */
131 | public MessageSearchParams withReceivedAfter(long receivedAfter) {
132 | this.receivedAfter = receivedAfter;
133 | return this;
134 | }
135 |
136 | /**
137 | * Sets the page index, used in conjunction with `itemsPerPage` to support pagination.
138 | *
139 | * @param page Used in conjunction with `itemsPerPage` to support pagination.
140 | * @return the MessageSearchParams object itself.
141 | */
142 | public MessageSearchParams withPage(int page) {
143 | this.page = page;
144 | return this;
145 | }
146 |
147 | /**
148 | * Set the limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
149 | *
150 | * @param itemsPerPage A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
151 | * @return the MessageSearchParams object itself.
152 | */
153 | public MessageSearchParams withItemsPerPage(int itemsPerPage) {
154 | this.itemsPerPage = itemsPerPage;
155 | return this;
156 | }
157 |
158 | /**
159 | * Sets how long to wait for a matching result (in milliseconds).
160 | *
161 | * @param timeout The time to wait for a matching result (in milliseconds).
162 | * @return the MessageSearchParams object itself.
163 | */
164 | public MessageSearchParams withTimeout(int timeout) {
165 | this.timeout = timeout;
166 | return this;
167 | }
168 |
169 | /**
170 | * Set whether or not an error will not be throw if timeout is reached (default: true).
171 | *
172 | * @param errorOnTimeout When set to false, an error will not be throw if timeout is reached (default: true).
173 | * @return the MessageSearchParams object itself.
174 | */
175 | public MessageSearchParams withErrorOnTimeout(boolean errorOnTimeout) {
176 | this.errorOnTimeout = errorOnTimeout;
177 | return this;
178 | }
179 |
180 | /**
181 | * Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
182 | *
183 | * @param dir Can be either `Sent` or `Received`, with the default being `Received`.
184 | * @return the MessageSearchParams object itself.
185 | */
186 | public MessageSearchParams withDir(String dir) {
187 | this.dir = dir;
188 | return this;
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/MessageSummary.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 |
5 | import com.google.api.client.util.DateTime;
6 | import com.google.api.client.util.Key;
7 |
8 | /**
9 | * The MessageSummary model.
10 | */
11 | public class MessageSummary extends BaseModel {
12 | /**
13 | * Unique identifier for the message.
14 | */
15 | @Key
16 | private String id;
17 |
18 | /**
19 | * The type of message.
20 | */
21 | @Key
22 | private String type;
23 |
24 | /**
25 | * The sender of the message.
26 | */
27 | @Key
28 | private List from;
29 |
30 | /**
31 | * The recipients of the message.
32 | */
33 | @Key
34 | private List to;
35 |
36 | /**
37 | * Carbon-copied recipients for email messages.
38 | */
39 | @Key
40 | private List cc;
41 |
42 | /**
43 | * Blind carbon-copied recipients for email messages.
44 | */
45 | @Key
46 | private List bcc;
47 |
48 | /**
49 | * The date/time that this message was received by Mailosaur.
50 | */
51 | @Key
52 | private DateTime received;
53 |
54 | /**
55 | * The subject of the message.
56 | */
57 | @Key
58 | private String subject;
59 |
60 | /**
61 | * A short, summarized version of the message content.
62 | */
63 | @Key
64 | private String summary;
65 |
66 | /**
67 | * The number of attachments associated with the message.
68 | */
69 | @Key
70 | private Integer attachments;
71 |
72 | /**
73 | * Identifier for the server in which the message is located.
74 | */
75 | @Key
76 | private String server;
77 |
78 | /**
79 | * Get the unique identifier for the message.
80 | *
81 | * @return Unique identifier for the message.
82 | */
83 | public String id() {
84 | return this.id;
85 | }
86 |
87 | /**
88 | * Gets the type of message.
89 | *
90 | * @return The type of message.
91 | */
92 | public String type() {
93 | return this.type;
94 | }
95 |
96 | /**
97 | * Gets the sender of the message.
98 | *
99 | * @return The sender of the message.
100 | */
101 | public List from() {
102 | return this.from;
103 | }
104 |
105 | /**
106 | * Gets the recipients of the message.
107 | *
108 | * @return The recipients of the message.
109 | */
110 | public List to() {
111 | return this.to;
112 | }
113 |
114 | /**
115 | * Gets the carbon-copied recipients for email messages.
116 | *
117 | * @return The carbon-copied recipients for email messages.
118 | */
119 | public List cc() {
120 | return this.cc;
121 | }
122 |
123 | /**
124 | * Gets the blind carbon-copied recipients for email messages.
125 | *
126 | * @return The blind carbon-copied recipients for email messages.
127 | */
128 | public List bcc() {
129 | return this.bcc;
130 | }
131 |
132 | /**
133 | * Gets the date/time that this message was received by Mailosaur.
134 | *
135 | * @return The date/time that this message was received by Mailosaur.
136 | */
137 | public DateTime received() {
138 | return this.received;
139 | }
140 |
141 | /**
142 | * Gets the subject of the message.
143 | *
144 | * @return The subject of the message.
145 | */
146 | public String subject() {
147 | return nullableString(this.subject);
148 | }
149 |
150 | /**
151 | * Gets a short, summarized version of the message content.
152 | *
153 | * @return A short, summarized version of the message content.
154 | */
155 | public String summary() {
156 | return nullableString(this.summary);
157 | }
158 |
159 | /**
160 | * Gets the number of attachments associated with the message.
161 | *
162 | * @return The number of attachments associated with the message.
163 | */
164 | public Integer attachments() {
165 | return this.attachments;
166 | }
167 |
168 | /**
169 | * Gets the identifier for the server in which the message is located.
170 | *
171 | * @return Identifier for the server in which the message is located.
172 | */
173 | public String server() {
174 | return this.server;
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/Metadata.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | * Further metadata related to the message, including email headers.
8 | */
9 | public class Metadata extends BaseModel {
10 | /**
11 | * Message headers
12 | */
13 | @Key
14 | private List headers;
15 |
16 | /**
17 | * Gets the message headers.
18 | *
19 | * @return The message headers.
20 | */
21 | public List headers() {
22 | return this.headers;
23 | }
24 |
25 | /**
26 | * The fully-qualified domain name or IP address that was provided with the
27 | * Extended HELLO (EHLO) or HELLO (HELO) command. This value is generally
28 | * used to identify the SMTP client.
29 | * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.1
30 | */
31 | @Key
32 | private String helo;
33 |
34 | /**
35 | * Gets the fully-qualified domain name or IP address that was provided with the
36 | * Extended HELLO (EHLO) or HELLO (HELO) command. This value is generally
37 | * used to identify the SMTP client.
38 | *
39 | * @return The fully-qualified domain name or IP address that was provided with the
40 | * Extended HELLO (EHLO) or HELLO (HELO) command.
41 | */
42 | public String helo() {
43 | return nullableString(this.helo);
44 | }
45 |
46 | /**
47 | * The source mailbox/email address, referred to as the 'reverse-path',
48 | * provided via the MAIL command during the SMTP transaction.
49 | * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.2
50 | */
51 | @Key
52 | private String mailFrom;
53 |
54 | /**
55 | * Gets the source mailbox/email address, referred to as the 'reverse-path',
56 | * provided via the MAIL command during the SMTP transaction.
57 | * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.2
58 | *
59 | * @return The source mailbox/email address, referred to as the 'reverse-path',
60 | * provided via the MAIL command during the SMTP transaction.
61 | */
62 | public String mailFrom() {
63 | return nullableString(this.mailFrom);
64 | }
65 |
66 | /**
67 | * The recipient email addresses, each referred to as a 'forward-path',
68 | * provided via the RCPT command during the SMTP transaction.
69 | * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.3
70 | */
71 | @Key
72 | private List rcptTo;
73 |
74 | /**
75 | * Gets the recipient email addresses, each referred to as a 'forward-path',
76 | * provided via the RCPT command during the SMTP transaction.
77 | * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.1.3
78 | *
79 | * @return Gets the recipient email addresses, each referred to as a 'forward-path',
80 | * provided via the RCPT command during the SMTP transaction.
81 | */
82 | public List rcptTo() {
83 | return this.rcptTo;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/OtpResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.DateTime;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | * Mailosaur virtual security device.
8 | */
9 | public class OtpResult {
10 | /**
11 | * The current one-time password.
12 | */
13 | @Key
14 | private String code;
15 |
16 | /**
17 | * The expiry date/time of the current one-time password.
18 | */
19 | @Key
20 | private DateTime expires;
21 |
22 | /**
23 | * Gets the current one-time password.
24 | *
25 | * @return The current one-time password.
26 | */
27 | public String code() {
28 | return this.code;
29 | }
30 |
31 | /**
32 | * Gets the expiry date/time of the current one-time password.
33 | *
34 | * @return The expiry date/time of the current one-time password.
35 | */
36 | public DateTime expires() {
37 | return this.expires;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/Preview.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Describes an email preview.
7 | */
8 | public class Preview {
9 | /**
10 | * Unique identifier for the email preview.
11 | */
12 | @Key
13 | private String id;
14 |
15 | /**
16 | * The email client the preview was generated with.
17 | */
18 | @Key
19 | private String emailClient;
20 |
21 | /**
22 | * True if images were disabled in the preview.
23 | */
24 | @Key
25 | private Boolean disableImages;
26 |
27 | /**
28 | * Gets the unique identifier for the email preview.
29 | *
30 | * @return The unique identifier for the email preview.
31 | */
32 | public String id() {
33 | return this.id;
34 | }
35 |
36 | /**
37 | * Gets the email client the preview was generated with.
38 | *
39 | * @return The email client the preview was generated with.
40 | */
41 | public String emailClient() {
42 | return this.emailClient;
43 | }
44 |
45 | /**
46 | * True if images were disabled in the preview.
47 | *
48 | * @return True if images were disabled in the preview.
49 | */
50 | public Boolean disableImages() {
51 | return this.disableImages;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/PreviewEmailClient.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Describes an email client with which email previews can be generated.
7 | */
8 | public class PreviewEmailClient {
9 | /**
10 | * The unique identifier of the email client.
11 | */
12 | @Key
13 | private String id;
14 |
15 | /**
16 | * The display name of the email client.
17 | */
18 | @Key
19 | private String name;
20 |
21 | /**
22 | * Whether the platform is desktop, mobile, or web-based.
23 | */
24 | @Key
25 | private String platformGroup;
26 |
27 | /**
28 | * The type of platform on which the email client is running.
29 | */
30 | @Key
31 | private String platformType;
32 |
33 | /**
34 | * The platform version number.
35 | */
36 | @Key
37 | private String platformVersion;
38 |
39 | /**
40 | * If true, images can be disabled when generating previews.
41 | */
42 | @Key
43 | private Boolean canDisableImages;
44 |
45 | /**
46 | * The current status of the email client.
47 | */
48 | @Key
49 | private String status;
50 |
51 | /**
52 | * Gets the unique identifier of the email client.
53 | *
54 | * @return The unique identifier of the email client.
55 | */
56 | public String id() {
57 | return this.id;
58 | }
59 |
60 | /**
61 | * Gets the display name of the email client.
62 | *
63 | * @return The display name of the email client.
64 | */
65 | public String name() {
66 | return this.name;
67 | }
68 |
69 | /**
70 | * Gets whether the platform is desktop, mobile, or web-based.
71 | *
72 | * @return Whether the platform is desktop, mobile, or web-based.
73 | */
74 | public String platformGroup() {
75 | return this.platformGroup;
76 | }
77 |
78 | /**
79 | * Gets the type of platform on which the email client is running.
80 | *
81 | * @return The type of platform on which the email client is running.
82 | */
83 | public String platformType() {
84 | return this.platformType;
85 | }
86 |
87 | /**
88 | * Gets the platform version number.
89 | *
90 | * @return The platform version number.
91 | */
92 | public String platformVersion() {
93 | return this.platformVersion;
94 | }
95 |
96 | /**
97 | * If true, images can be disabled when generating previews.
98 | *
99 | * @return If true, images can be disabled when generating previews.
100 | */
101 | public Boolean canDisableImages() {
102 | return this.canDisableImages;
103 | }
104 |
105 | /**
106 | * Gets the current status of the email client.
107 | *
108 | * @return The current status of the email client.
109 | */
110 | public String status() {
111 | return this.status;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/PreviewEmailClientListResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * A list of available email clients with which to generate email previews.
9 | */
10 | public class PreviewEmailClientListResult {
11 | /**
12 | * A list of available email clients with which to generate email previews.
13 | */
14 | @Key
15 | private List items;
16 |
17 | /**
18 | * Gets a list of available email clients.
19 | *
20 | * @return A list of available email clients.
21 | */
22 | public List items() {
23 | return this.items;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/PreviewListResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * The result of a preview listing operation.
9 | */
10 | public class PreviewListResult {
11 | /**
12 | * A list of requested email previews.
13 | */
14 | @Key
15 | private List items;
16 |
17 | /**
18 | * Gets a list of requested email previews.
19 | *
20 | * @return A list of requested email previews.
21 | */
22 | public List items() {
23 | return this.items;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/PreviewRequest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Describes an email preview request.
7 | */
8 | public class PreviewRequest {
9 | /**
10 | * The email client you wish to generate a preview for.
11 | */
12 | @Key
13 | private String emailClient;
14 |
15 | /**
16 | * If true, images will be disabled (only if supported by the client).
17 | */
18 | @Key
19 | private Boolean disableImages;
20 |
21 | public PreviewRequest(String emailClient) {
22 | this.emailClient = emailClient;
23 | this.disableImages = false;
24 | }
25 |
26 | public PreviewRequest(String emailClient, Boolean disableImages) {
27 | this.emailClient = emailClient;
28 | this.disableImages = disableImages;
29 | }
30 |
31 | /**
32 | * Sets the email client you wish to generate a preview for.
33 | *
34 | * @param emailClient The email client you wish to generate a preview for.
35 | * @return the PreviewRequest object itself.
36 | */
37 | public PreviewRequest withEmailClient(String emailClient) {
38 | this.emailClient = emailClient;
39 | return this;
40 | }
41 |
42 | /**
43 | * Sets whether images should be disabled in the preview (only if supported by the client).
44 | *
45 | * @param disableImages If true, images will be disabled (only if supported by the client).
46 | * @return the PreviewRequest object itself.
47 | */
48 | public PreviewRequest withDisableImages(Boolean disableImages) {
49 | this.disableImages = disableImages;
50 | return this;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/PreviewRequestOptions.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Preview request options.
9 | */
10 | public class PreviewRequestOptions {
11 | /**
12 | * The list of email preview requests.
13 | */
14 | @Key
15 | private List previews;
16 |
17 | /**
18 | * Sets the list of email preview requests.
19 | *
20 | * @param previews The list of email preview requests.
21 | * @return the PreviewRequestOptions object itself.
22 | */
23 | public PreviewRequestOptions withPreviews(List previews) {
24 | this.previews = previews;
25 | return this;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/SearchCriteria.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * The criteria with which to find messages during a search.
7 | */
8 | public class SearchCriteria {
9 | /**
10 | * The full email address (or phone number for SMS) from which the target message was sent.
11 | */
12 | @Key
13 | private String sentFrom;
14 |
15 | /**
16 | * The full email address (or phone number for SMS) to which the target message was sent.
17 | */
18 | @Key
19 | private String sentTo;
20 |
21 | /**
22 | * The value to seek within the subject line of a target email.
23 | */
24 | @Key
25 | private String subject;
26 |
27 | /**
28 | * The value to seek within the body of the target message.
29 | */
30 | @Key
31 | private String body;
32 |
33 | /**
34 | * If set to `ALL` (default), then only results that match all specified criteria will be returned.
35 | * If set to `ANY`, results that match any of the specified criteria will be returned.
36 | */
37 | @Key
38 | private SearchMatchOperator match;
39 |
40 | /**
41 | * Sets the full email address (or phone number for SMS) from which the target message was sent.
42 | *
43 | * @param sentFrom Email address (or phone number for SMS).
44 | * @return the SearchCriteria object itself.
45 | */
46 | public SearchCriteria withSentFrom(String sentFrom) {
47 | this.sentFrom = sentFrom;
48 | return this;
49 | }
50 |
51 | /**
52 | * Sets the full email address (or phone number for SMS) to which the target message was sent.
53 | *
54 | * @param sentTo Email address (or phone number for SMS).
55 | * @return the SearchCriteria object itself.
56 | */
57 | public SearchCriteria withSentTo(String sentTo) {
58 | this.sentTo = sentTo;
59 | return this;
60 | }
61 |
62 | /**
63 | * Sets the value to seek within the subject line of a target email.
64 | *
65 | * @param subject The value to seek within the subject line of a target email.
66 | * @return the SearchCriteria object itself.
67 | */
68 | public SearchCriteria withSubject(String subject) {
69 | this.subject = subject;
70 | return this;
71 | }
72 |
73 | /**
74 | * Sets the value to seek within the body of the target message.
75 | *
76 | * @param body The value to seek within the body of the target message.
77 | * @return the SearchCriteria object itself.
78 | */
79 | public SearchCriteria withBody(String body) {
80 | this.body = body;
81 | return this;
82 | }
83 |
84 | /**
85 | * If set to `ALL` (default), then only results that match all specified criteria will be returned.
86 | * If set to `ANY`, results that match any of the specified criteria will be returned.
87 | *
88 | * @param match Match `ALL` or `ANY` of the specified criteria.
89 | * @return the SearchCriteria object itself.
90 | */
91 | public SearchCriteria withMatch(SearchMatchOperator match) {
92 | this.match = match;
93 | return this;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/SearchMatchOperator.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Value;
4 |
5 | public enum SearchMatchOperator {
6 | @Value("ALL")
7 | ALL,
8 | @Value("ANY")
9 | ANY
10 | }
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/Server.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | * Mailosaur virtual SMTP/SMS server.
8 | */
9 | public class Server {
10 | /**
11 | * Unique identifier for the server.
12 | */
13 | @Key
14 | private String id;
15 |
16 | /**
17 | * The name of the server.
18 | */
19 | @Key
20 | private String name;
21 |
22 | /**
23 | * Users (excluding administrators) who have access to the server (if it is restricted).
24 | */
25 | @Key
26 | private List users;
27 |
28 | /**
29 | * The number of messages currently in the server.
30 | */
31 | @Key
32 | private Integer messages;
33 |
34 | /**
35 | * Gets the unique identifier of the server.
36 | *
37 | * @return The server ID.
38 | */
39 | public String id() {
40 | return this.id;
41 | }
42 |
43 | /**
44 | * Gets the name of the server.
45 | *
46 | * @return The name of the server.
47 | */
48 | public String name() {
49 | return this.name;
50 | }
51 |
52 | /**
53 | * Sets the name of the server.
54 | *
55 | * @param name The name of the server.
56 | * @return the Server object itself.
57 | */
58 | public Server withName(String name) {
59 | this.name = name;
60 | return this;
61 | }
62 |
63 | /**
64 | * Gets the IDs of users who have access to the server (if it is restricted).
65 | *
66 | * @return The IDs of users who have access to the server (if it is restricted).
67 | */
68 | public List users() {
69 | return this.users;
70 | }
71 |
72 | /**
73 | * Sets the IDs of users who have access to the server (if it is restricted).
74 | *
75 | * @param users The IDs of users who have access to the server (if it is restricted).
76 | * @return the Server object itself.
77 | */
78 | public Server withUsers(List users) {
79 | this.users = users;
80 | return this;
81 | }
82 |
83 | /**
84 | * Gets the number of messages currently in the server.
85 | *
86 | * @return The number of messages currently in the server.
87 | */
88 | public Integer messages() {
89 | return this.messages;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/ServerCreateOptions.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * Options used to create a new Mailosaur server.
7 | */
8 | public class ServerCreateOptions {
9 | /**
10 | * A name used to identify the server.
11 | */
12 | @Key
13 | private String name;
14 |
15 | /**
16 | * Sets a name used to identify the server.
17 | *
18 | * @param name A name used to identify the server.
19 | * @return the ServerCreateOptions object itself.
20 | */
21 | public ServerCreateOptions withName(String name) {
22 | this.name = name;
23 | return this;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/ServerListResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 |
5 | import com.google.api.client.util.Key;
6 |
7 | /**
8 | * The result of the server listing operation.
9 | */
10 | public class ServerListResult {
11 | /**
12 | * The individual servers forming the result. Servers
13 | * are returned sorted by creation date, with the most recently-created server
14 | * appearing first.
15 | */
16 | @Key
17 | private List items;
18 |
19 | /**
20 | * Gets the individual servers forming the result.
21 | *
22 | * @return The individual servers forming the result.
23 | */
24 | public List items() {
25 | return this.items;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/SpamAnalysisResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * The results of spam analysis performed by Mailosaur.
7 | */
8 | public class SpamAnalysisResult {
9 | /**
10 | * Spam filter results.
11 | */
12 | @Key
13 | private SpamFilterResults spamFilterResults;
14 |
15 | /**
16 | * Overall Mailosaur spam score.
17 | */
18 | @Key
19 | private Double score;
20 |
21 | /**
22 | * Gets the Spam filter results.
23 | *
24 | * @return Spam filter results.
25 | */
26 | public SpamFilterResults spamFilterResults() {
27 | return this.spamFilterResults;
28 | }
29 |
30 | /**
31 | * Gets the overall Mailosaur spam score.
32 | *
33 | * @return The overall Mailosaur spam score.
34 | */
35 | public Double score() {
36 | return this.score;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/SpamAssassinResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 |
5 | import com.google.api.client.util.Key;
6 |
7 | /**
8 | * The results of spam assassin check performed by Mailosaur.
9 | */
10 | public class SpamAssassinResult {
11 |
12 | /**
13 | * Overall Mailosaur spam score.
14 | */
15 | @Key
16 | private Double score;
17 |
18 | /**
19 | * The result of the spam check
20 | */
21 | @Key
22 | private String result;
23 |
24 | /**
25 | * Spam Assassin filter results.
26 | */
27 | @Key
28 | private List rules;
29 |
30 |
31 | /**
32 | * Gets the overall spam score
33 | *
34 | * @return The overall spam score
35 | */
36 | public Double score() {
37 | return score;
38 | }
39 |
40 | /**
41 | * Gets the success/failure result of the spam check
42 | *
43 | * @return The result of the spam check
44 | */
45 | public String result() {
46 | return result;
47 | }
48 |
49 | /**
50 | * Gets the Spam Assassin filter results.
51 | *
52 | * @return The Spam Assassin filter results.
53 | */
54 | public List rules() {
55 | return rules;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/SpamAssassinRule.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * The result of an individual Spam Assassin rule
7 | */
8 | public class SpamAssassinRule {
9 | /**
10 | * Spam Assassin rule score.
11 | */
12 | @Key
13 | private Double score;
14 |
15 | /**
16 | * Spam Assassin rule name.
17 | */
18 | @Key
19 | private String rule;
20 |
21 | /**
22 | * Spam Assassin rule description.
23 | */
24 | @Key
25 | private String description;
26 |
27 | /**
28 | * Gets the Spam Assassin rule score.
29 | *
30 | * @return The Spam Assassin rule score.
31 | */
32 | public Double score() {
33 | return this.score;
34 | }
35 |
36 | /**
37 | * Gets the Spam Assassin rule name.
38 | *
39 | * @return The Spam Assassin rule name.
40 | */
41 | public String rule() {
42 | return this.rule;
43 | }
44 |
45 | /**
46 | * Gets the Spam Assassin rule description.
47 | *
48 | * @return The Spam Assassin rule description.
49 | */
50 | public String description() {
51 | return this.description;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/SpamFilterResults.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 |
5 | import com.google.api.client.util.Key;
6 |
7 | /**
8 | * Results for this email against various spam filters.
9 | */
10 | public class SpamFilterResults {
11 | /**
12 | * Spam Assassin filter results.
13 | */
14 | @Key
15 | private List spamAssassin;
16 |
17 | /**
18 | * Gets the Spam Assassin filter results.
19 | *
20 | * @return The Spam Assassin filter results.
21 | */
22 | public List spamAssassin() {
23 | return this.spamAssassin;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/UsageAccountLimit.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * The detail of an individual account limit.
7 | */
8 | public class UsageAccountLimit {
9 | /**
10 | * The limit for your account.
11 | */
12 | @Key
13 | private Integer limit;
14 |
15 | /**
16 | * Your account usage so far.
17 | */
18 | @Key
19 | private Integer current;
20 |
21 | /**
22 | * Gets the limit for your account.
23 | *
24 | * @return The limit for your account.
25 | */
26 | public Integer limit() {
27 | return this.limit;
28 | }
29 |
30 | /**
31 | * Gets your account usage so far.
32 | *
33 | * @return Your account usage so far.
34 | */
35 | public Integer current() {
36 | return this.current;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/UsageAccountLimits.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.Key;
4 |
5 | /**
6 | * The current limits and usage for your account.
7 | */
8 | public class UsageAccountLimits {
9 | /**
10 | * Server limits.
11 | */
12 | @Key
13 | private UsageAccountLimit servers;
14 |
15 | /**
16 | * User limits.
17 | */
18 | @Key
19 | private UsageAccountLimit users;
20 |
21 | /**
22 | * Emails per day limits.
23 | */
24 | @Key
25 | private UsageAccountLimit email;
26 |
27 | /**
28 | * SMS message per month limits.
29 | */
30 | @Key
31 | private UsageAccountLimit sms;
32 |
33 | /**
34 | * Gets server limits.
35 | *
36 | * @return Server limits.
37 | */
38 | public UsageAccountLimit servers() {
39 | return this.servers;
40 | }
41 |
42 | /**
43 | * Gets user limits.
44 | *
45 | * @return User limits.
46 | */
47 | public UsageAccountLimit users() {
48 | return this.users;
49 | }
50 |
51 | /**
52 | * Gets emails per day limits.
53 | *
54 | * @return Emails per day limits.
55 | */
56 | public UsageAccountLimit email() {
57 | return this.email;
58 | }
59 |
60 | /**
61 | * Gets SMS message per month limits.
62 | *
63 | * @return SMS message per month limits.
64 | */
65 | public UsageAccountLimit sms() {
66 | return this.sms;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/UsageTransaction.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import com.google.api.client.util.DateTime;
4 | import com.google.api.client.util.Key;
5 |
6 | /**
7 | * Usage transaction.
8 | */
9 | public class UsageTransaction {
10 | /**
11 | * The date/time of the transaction.
12 | */
13 | @Key
14 | private DateTime timestamp;
15 |
16 | /**
17 | * The number of emails.
18 | */
19 | @Key
20 | private Integer email;
21 |
22 | /**
23 | * The number of SMS messages.
24 | */
25 | @Key
26 | private Integer sms;
27 |
28 | /**
29 | * Gets the date/time of the transaction.
30 | *
31 | * @return The date/time of the transaction.
32 | */
33 | public DateTime timestamp() {
34 | return this.timestamp;
35 | }
36 |
37 | /**
38 | * Gets the number of emails.
39 | *
40 | * @return The number of emails.
41 | */
42 | public Integer email() {
43 | return this.email;
44 | }
45 |
46 | /**
47 | * Gets the number of SMS messages.
48 | *
49 | * @return The number of SMS messages.
50 | */
51 | public Integer sms() {
52 | return this.sms;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/UsageTransactionListResult.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur.models;
2 |
3 | import java.util.List;
4 |
5 | import com.google.api.client.util.Key;
6 |
7 | /**
8 | * Usage transactions from your account.
9 | */
10 | public class UsageTransactionListResult {
11 | /**
12 | * The individual transactions that have occurred.
13 | */
14 | @Key
15 | private List items;
16 |
17 | /**
18 | * Gets the individual transactions that have occurred.
19 | *
20 | * @return The individual transactions that have occurred.
21 | */
22 | public List items() {
23 | return this.items;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/models/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains the models classes for MailosaurClient.
3 | * # Introduction
4 | This is an overview of the Mailosaur API. This API a RESTful JSON interface
5 | with predictable, resource-oriented URLs. We make use of HTTP response codes to indicate
6 | API errors.
7 | We use built-in HTTP features, like HTTP authentication and HTTP verbs, which are understood
8 | by off-the-shelf HTTP clients.
9 | [Official client libraries](#) available for most popular languages.
10 | # Authentication
11 | Authenticate your account when using the API by including your API key in the request.
12 | You can manage your API keys in the Mailosaur UI. Your API key carrys many privileges,
13 | so be sure to keep it secret! Do not share your API key in publicly-accessible areas such
14 | GitHub, client-side code, and so on.
15 | All API requests must be made over HTTPS. Calls made over plain HTTP will fail.
16 | API requests without authentication will also fail.
17 | # Errors
18 | ## HTTP status codes
19 | Mailosaur uses conventional HTTP response codes to indicate the success or failure of an
20 | API request. In general, codes in the `2xx` range indicate success, codes in the `4xx` range
21 | indicate an error that failed given the information provided (e.g., a required parameter
22 | was omitted), and codes in the `5xx` range indicate an error with
23 | Mailosaur's servers (give us a shout in the unlikely event that you see one of those).
24 | | Code | Description |
25 | |---|---|
26 | | 200 - OK | Request was successful. |
27 | | 204 - No Content | Request was successful, no response content. |
28 | | 400 - Bad Request | The request could be handled, often due to missing a required parameter. |
29 | | 401 - Unauthorized | No valid API key provided. |
30 | | 404 - Not Found | The requested resource doesn't exist. |
31 | | 5XX - Server Errors | Something went wrong at Mailosaur. (Give us a shout). |
32 | ## Error handling
33 | In of an error the server will return as much information as possible. In the case of a `401` or
34 | `404` error the status code gives as much information as you'd need. But for `400` errors
35 | Mailosaur will return a JSON object containing the structure below.
36 | Note that our client libraries convert responses to appropriate language-specific objects.
37 | | Property | Description |
38 | |---|---|
39 | | `type` | The type of error returned. Can be: api_connection_error, api_error, authentication_error, card_error, idempotency_error invalid_request_error, or rate_limit_error. |
40 | | `message` | A human-readable message providing more details about the error. |
41 | | `parameters` | A JSON object containing a key for each property name at fault, with a human-readable message per field |
42 | | `model` | The request model that we sent and failed to be processed |.
43 | */
44 | package com.mailosaur.models;
45 |
--------------------------------------------------------------------------------
/src/main/java/com/mailosaur/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This package contains the classes for MailosaurClient.
3 | * # Introduction
4 | This is an overview of the Mailosaur API. This API a RESTful JSON interface
5 | with predictable, resource-oriented URLs. We make use of HTTP response codes to indicate
6 | API errors.
7 | We use built-in HTTP features, like HTTP authentication and HTTP verbs, which are understood
8 | by off-the-shelf HTTP clients.
9 | [Official client libraries](#) available for most popular languages.
10 | # Authentication
11 | Authenticate your account when using the API by including your API key in the request.
12 | You can manage your API keys in the Mailosaur UI. Your API key carrys many privileges,
13 | so be sure to keep it secret! Do not share your API key in publicly-accessible areas such
14 | GitHub, client-side code, and so on.
15 | All API requests must be made over HTTPS. Calls made over plain HTTP will fail.
16 | API requests without authentication will also fail.
17 | # Errors
18 | ## HTTP status codes
19 | Mailosaur uses conventional HTTP response codes to indicate the success or failure of an
20 | API request. In general, codes in the `2xx` range indicate success, codes in the `4xx` range
21 | indicate an error that failed given the information provided (e.g., a required parameter
22 | was omitted), and codes in the `5xx` range indicate an error with
23 | Mailosaur's servers (give us a shout in the unlikely event that you see one of those).
24 | | Code | Description |
25 | |---|---|
26 | | 200 - OK | Request was successful. |
27 | | 204 - No Content | Request was successful, no response content. |
28 | | 400 - Bad Request | The request could be handled, often due to missing a required parameter. |
29 | | 401 - Unauthorized | No valid API key provided. |
30 | | 404 - Not Found | The requested resource doesn't exist. |
31 | | 5XX - Server Errors | Something went wrong at Mailosaur. (Give us a shout). |
32 | ## Error handling
33 | In of an error the server will return as much information as possible. In the case of a `401` or
34 | `404` error the status code gives as much information as you'd need. But for `400` errors
35 | Mailosaur will return a JSON object containing the structure below.
36 | Note that our client libraries convert responses to appropriate language-specific objects.
37 | | Property | Description |
38 | |---|---|
39 | | `type` | The type of error returned. Can be: api_connection_error, w, authentication_error, card_error, idempotency_error invalid_request_error, or rate_limit_error. |
40 | | `message` | A human-readable message providing more details about the error. |
41 | | `parameters` | A JSON object containing a key for each property name at fault, with a human-readable message per field |
42 | | `model` | The request model that we sent and failed to be processed |.
43 | */
44 | package com.mailosaur;
45 |
--------------------------------------------------------------------------------
/src/main/main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/DevicesTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import com.mailosaur.models.Device;
4 | import com.mailosaur.models.DeviceCreateOptions;
5 | import com.mailosaur.models.DeviceListResult;
6 | import com.mailosaur.models.OtpResult;
7 | import org.junit.BeforeClass;
8 | import org.junit.Test;
9 |
10 | import javax.mail.MessagingException;
11 | import java.io.IOException;
12 |
13 | import static org.junit.Assert.*;
14 |
15 | public class DevicesTest {
16 | private static MailosaurClient client;
17 |
18 | @BeforeClass
19 | public static void setUpBeforeClass() throws IOException {
20 | String apiKey = System.getenv("MAILOSAUR_API_KEY");
21 | String baseUrl = System.getenv("MAILOSAUR_BASE_URL");
22 |
23 | if (apiKey == null) {
24 | throw new IOException("Missing necessary environment variables - refer to README.md");
25 | }
26 |
27 | client = new MailosaurClient(apiKey, baseUrl);
28 | }
29 |
30 | @Test
31 | public void testCrud() throws IOException, MailosaurException {
32 | String deviceName = "My test";
33 | String sharedSecret = "ONSWG4TFOQYTEMY=";
34 |
35 | // Create a new device
36 | DeviceCreateOptions options = new DeviceCreateOptions()
37 | .withName(deviceName)
38 | .withSharedSecret(sharedSecret);
39 | Device createdDevice = client.devices().create(options);
40 | assertNotNull(createdDevice.id());
41 | assertEquals(deviceName, createdDevice.name());
42 |
43 | // Retrieve an otp via device ID
44 | OtpResult otpResult = client.devices().otp(createdDevice.id());
45 | assertEquals(6, otpResult.code().length());
46 |
47 | DeviceListResult before = client.devices().list();
48 | assertTrue(before.items().stream().anyMatch(x -> x.id().equals(createdDevice.id())));
49 |
50 | client.devices().delete(createdDevice.id());
51 |
52 | DeviceListResult after = client.devices().list();
53 | assertFalse(after.items().stream().anyMatch(x -> x.id().equals(createdDevice.id())));
54 | }
55 |
56 | @Test
57 | public void testOtpViaSharedSecret() throws IOException, MailosaurException {
58 | String sharedSecret = "ONSWG4TFOQYTEMY=";
59 |
60 | OtpResult otpResult = client.devices().otp(sharedSecret);
61 | assertEquals(6, otpResult.code().length());
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/EmailsTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import static java.lang.System.currentTimeMillis;
4 | import static org.junit.Assert.*;
5 |
6 | import java.io.IOException;
7 | import java.nio.file.Files;
8 | import java.nio.file.Path;
9 | import java.nio.file.Paths;
10 | import java.time.Instant;
11 | import java.util.*;
12 | import java.util.stream.Stream;
13 | import javax.mail.MessagingException;
14 |
15 | import com.mailosaur.models.*;
16 | import org.junit.BeforeClass;
17 | import org.junit.Test;
18 |
19 | public class EmailsTest {
20 | private static MailosaurClient client;
21 | private static String server;
22 | private static String verifiedDomain;
23 | private static List emails;
24 | private final String isoDateString = Instant.now().toString().substring(0, 10);
25 |
26 | @BeforeClass
27 | public static void setUpBeforeClass() throws IOException, MessagingException, MailosaurException {
28 | server = System.getenv("MAILOSAUR_SERVER");
29 | verifiedDomain = System.getenv("MAILOSAUR_VERIFIED_DOMAIN");
30 | String apiKey = System.getenv("MAILOSAUR_API_KEY");
31 | String baseUrl = System.getenv("MAILOSAUR_BASE_URL");
32 |
33 | if (apiKey == null || server == null) {
34 | throw new IOException("Missing necessary environment variables - refer to README.md");
35 | }
36 |
37 | client = new MailosaurClient(apiKey, baseUrl);
38 |
39 | client.messages().deleteAll(server);
40 |
41 | Mailer.sendEmails(client, server, 5);
42 |
43 | MessageListParams params = new MessageListParams();
44 | params.withServer(server);
45 | emails = client.messages().list(params).items();
46 | }
47 |
48 | @Test
49 | public void testList() {
50 | assertEquals(5, emails.size());
51 | for (MessageSummary email : emails) {
52 | validateEmailSummary(email);
53 | }
54 | }
55 |
56 | @Test
57 | public void testListReceivedAfter() throws IOException, MailosaurException {
58 | long pastDate = currentTimeMillis() - 600000; // now less 10 minutes
59 |
60 | MessageListParams pastParams = new MessageListParams();
61 | pastParams.withServer(server).withReceivedAfter(pastDate);
62 | List pastEmails = client.messages().list(pastParams).items();
63 | assertTrue(pastEmails.size() > 0);
64 |
65 | MessageListParams futureParams = new MessageListParams();
66 | futureParams.withServer(server).withReceivedAfter(currentTimeMillis());
67 | List futureEmails = client.messages().list(futureParams).items();
68 | assertEquals(0, futureEmails.size());
69 | }
70 |
71 | @Test
72 | public void testGet() throws IOException, MessagingException, MailosaurException {
73 | String host = System.getenv("MAILOSAUR_SMTP_HOST");
74 | host = (host == null) ? "mailosaur.net" : host;
75 |
76 | String testEmailAddress = String.format("wait_for_test@%s.%s", server, host);
77 |
78 | Mailer.sendEmail(client, server, testEmailAddress);
79 |
80 | SearchCriteria criteria = new SearchCriteria();
81 | criteria.withSentTo(testEmailAddress);
82 |
83 | MessageSearchParams params = new MessageSearchParams();
84 | params.withServer(server);
85 | Message email = client.messages().get(params, criteria);
86 |
87 | validateEmail(email);
88 | }
89 |
90 | @Test
91 | public void testGetById() throws IOException, MailosaurException {
92 | MessageSummary emailToRetrieve = emails.get(0);
93 | Message email = client.messages().getById(emailToRetrieve.id());
94 | validateEmail(email);
95 | validateHeaders(email);
96 | }
97 |
98 | @Test(expected = MailosaurException.class)
99 | public void testGetByIdNotFound() throws IOException, MailosaurException {
100 | client.messages().getById("efe907e9-74ed-4113-a3e0-a3d41d914765");
101 | }
102 |
103 | @Test
104 | public void testSearchNoCriteria() throws IOException {
105 | try {
106 | MessageSearchParams params = new MessageSearchParams();
107 | params.withServer(server);
108 | client.messages().search(params, new SearchCriteria());
109 | throw new IOException("Should have thrown MailosaurException");
110 | } catch (MailosaurException e) { }
111 | }
112 |
113 | @Test
114 | public void testSearchTimeoutErrorSuppressed() throws IOException, MailosaurException {
115 | MessageSearchParams params = new MessageSearchParams();
116 | params.withServer(server)
117 | .withTimeout(1)
118 | .withErrorOnTimeout(false);
119 | SearchCriteria criteria = new SearchCriteria();
120 | criteria.withSentFrom("neverfound@example.com");
121 | List results = client.messages().search(params, criteria).items();
122 | assertEquals(0, results.size());
123 | }
124 |
125 | public void testSearchBySentFrom() throws IOException, MailosaurException {
126 | MessageSummary targetEmail = emails.get(1);
127 | MessageSearchParams params = new MessageSearchParams();
128 | params.withServer(server);
129 | SearchCriteria criteria = new SearchCriteria();
130 | criteria.withSentFrom(targetEmail.from().get(0).email());
131 | List results = client.messages().search(params, criteria).items();
132 | assertEquals(1, results.size());
133 | assertEquals(targetEmail.from().get(0).email(), results.get(0).from().get(0).email());
134 | assertEquals(targetEmail.subject(), results.get(0).subject());
135 | }
136 |
137 | @Test
138 | public void testSearchBySentTo() throws IOException, MailosaurException {
139 | MessageSummary targetEmail = emails.get(1);
140 | MessageSearchParams params = new MessageSearchParams();
141 | params.withServer(server);
142 | SearchCriteria criteria = new SearchCriteria();
143 | criteria.withSentTo(targetEmail.to().get(0).email());
144 | List results = client.messages().search(params, criteria).items();
145 | assertEquals(1, results.size());
146 | assertEquals(targetEmail.to().get(0).email(), results.get(0).to().get(0).email());
147 | assertEquals(targetEmail.subject(), results.get(0).subject());
148 | }
149 |
150 | @Test
151 | public void testSearchByBody() throws IOException, MailosaurException {
152 | MessageSummary targetEmail = emails.get(1);
153 | String uniqueString = targetEmail.subject().substring(0, targetEmail.subject().indexOf(" subject"));
154 | MessageSearchParams params = new MessageSearchParams();
155 | params.withServer(server);
156 | SearchCriteria criteria = new SearchCriteria();
157 | criteria.withBody(uniqueString += " html");
158 | List results = client.messages().search(params, criteria).items();
159 | assertEquals(1, results.size());
160 | assertEquals(targetEmail.to().get(0).email(), results.get(0).to().get(0).email());
161 | assertEquals(targetEmail.subject(), results.get(0).subject());
162 | }
163 |
164 | @Test
165 | public void testSearchBySubject() throws IOException, MailosaurException {
166 | MessageSummary targetEmail = emails.get(1);
167 | String uniqueString = targetEmail.subject().substring(0, targetEmail.subject().indexOf(" subject"));
168 | MessageSearchParams params = new MessageSearchParams();
169 | params.withServer(server);
170 | SearchCriteria criteria = new SearchCriteria();
171 | criteria.withSubject(uniqueString);
172 | List results = client.messages().search(params, criteria).items();
173 | assertEquals(1, results.size());
174 | assertEquals(targetEmail.to().get(0).email(), results.get(0).to().get(0).email());
175 | assertEquals(targetEmail.subject(), results.get(0).subject());
176 | }
177 |
178 | @Test
179 | public void testSearchWithMatchAll() throws IOException, MailosaurException {
180 | MessageSummary targetEmail = emails.get(1);
181 | String uniqueString = targetEmail.subject().substring(0, targetEmail.subject().indexOf(" subject"));
182 | MessageSearchParams params = new MessageSearchParams();
183 | params.withServer(server);
184 | SearchCriteria criteria = new SearchCriteria();
185 | criteria.withSubject(uniqueString)
186 | .withBody("this is a link")
187 | .withMatch(SearchMatchOperator.ALL);
188 | List results = client.messages().search(params, criteria).items();
189 | assertEquals(1, results.size());
190 | }
191 |
192 | @Test
193 | public void testSearchWithMatchAny() throws IOException, MailosaurException {
194 | MessageSummary targetEmail = emails.get(1);
195 | String uniqueString = targetEmail.subject().substring(0, targetEmail.subject().indexOf(" subject"));
196 | MessageSearchParams params = new MessageSearchParams();
197 | params.withServer(server);
198 | SearchCriteria criteria = new SearchCriteria();
199 | criteria.withSubject(uniqueString)
200 | .withBody("this is a link")
201 | .withMatch(SearchMatchOperator.ANY);
202 | List results = client.messages().search(params, criteria).items();
203 | assertEquals(6, results.size());
204 | }
205 |
206 | @Test
207 | public void testSearchWithSpecialCharacters() throws IOException, MailosaurException {
208 | MessageSearchParams params = new MessageSearchParams();
209 | params.withServer(server);
210 | SearchCriteria criteria = new SearchCriteria();
211 | criteria.withSubject("Search with ellipsis … and emoji 👨🏿🚒");
212 | List results = client.messages().search(params, criteria).items();
213 | assertEquals(0, results.size());
214 | }
215 |
216 | @Test
217 | public void testSpamAnalysis() throws IOException, MailosaurException {
218 | String targetId = emails.get(0).id();
219 | SpamAnalysisResult result = client.analysis().spam(targetId);
220 |
221 | for (SpamAssassinRule rule : result.spamFilterResults().spamAssassin()) {
222 | assertNotNull(rule.rule());
223 | assertNotNull(rule.description());
224 | }
225 | }
226 |
227 | @Test
228 | public void testDeliverabilityReport() throws IOException, MailosaurException {
229 | String targetId = emails.get(0).id();
230 | DeliverabilityReport result = client.analysis().deliverability(targetId);
231 |
232 | assertNotNull(result);
233 |
234 | assertNotNull(result.spf());
235 |
236 | assertNotNull(result.dkim());
237 | for (EmailAuthenticationResult dkim : result.dkim()) {
238 | assertNotNull(dkim);
239 | }
240 |
241 | assertNotNull(result.dmarc());
242 |
243 | assertNotNull(result.blockLists());
244 | for (BlockListResult blockList : result.blockLists()) {
245 | assertNotNull(blockList);
246 | assertNotNull(blockList.id());
247 | assertNotNull(blockList.name());
248 | }
249 |
250 | assertNotNull(result.content());
251 |
252 | assertNotNull(result.dnsRecords());
253 | assertNotNull(result.dnsRecords().a());
254 | assertNotNull(result.dnsRecords().mx());
255 | assertNotNull(result.dnsRecords().ptr());
256 |
257 | assertNotNull(result.spamAssassin());
258 | for (SpamAssassinRule rule : result.spamAssassin().rules()) {
259 | assertNotNull(rule.rule());
260 | assertNotNull(rule.description());
261 | }
262 | }
263 |
264 | @Test
265 | public void testDelete() throws IOException, MailosaurException {
266 | String targetEmailId = emails.get(4).id();
267 |
268 | client.messages().delete(targetEmailId);
269 |
270 | // Attempting to delete again should fail
271 | try {
272 | client.messages().delete(targetEmailId);
273 | throw new IOException("Should have thrown MailosaurException");
274 | } catch (MailosaurException e) { }
275 | }
276 |
277 | @Test
278 | public void testCreateSendText() throws IOException, MailosaurException {
279 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
280 |
281 | String subject = "New message";
282 |
283 | MessageCreateOptions options = new MessageCreateOptions();
284 | options.withTo(String.format("anything@%s", verifiedDomain))
285 | .withSend(true)
286 | .withSubject(subject)
287 | .withText("This is a new email");
288 |
289 | Message message = client.messages().create(server, options);
290 |
291 | assertNotNull(message.id());
292 | assertEquals(subject, message.subject());
293 | }
294 |
295 | @Test
296 | public void testCreateSendHtml() throws IOException, MailosaurException {
297 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
298 |
299 | String subject = "New HTML message";
300 |
301 | MessageCreateOptions options = new MessageCreateOptions();
302 | options.withTo(String.format("anything@%s", verifiedDomain))
303 | .withSend(true)
304 | .withSubject(subject)
305 | .withHtml("This is a new email.
");
306 |
307 | Message message = client.messages().create(server, options);
308 |
309 | assertNotNull(message.id());
310 | assertEquals(subject, message.subject());
311 | }
312 |
313 | @Test
314 | public void testCreateSendCc() throws IOException, MailosaurException {
315 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
316 |
317 | String subject = "CC message";
318 | String ccRecipient = String.format("someoneelse@%s", verifiedDomain);
319 | MessageCreateOptions options = new MessageCreateOptions();
320 | options.withTo(String.format("anything@%s", verifiedDomain))
321 | .withCc(ccRecipient)
322 | .withSend(true)
323 | .withSubject(subject)
324 | .withHtml("This is a new email.
");
325 |
326 | Message message = client.messages().create(server, options);
327 |
328 | assertNotNull(message.id());
329 | assertEquals(subject, message.subject());
330 | assertEquals(1, message.cc().size());
331 | assertEquals(ccRecipient, message.cc().get(0).email());
332 | }
333 |
334 | @Test
335 | public void testCreateSendWithAttachment() throws IOException, MailosaurException {
336 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
337 |
338 | String subject = "New message with attachment";
339 |
340 | byte[] data = Files.readAllBytes(getResourceFilePath("cat.png"));
341 |
342 | Attachment attachment = new Attachment();
343 | attachment.withFileName("cat.png");
344 | attachment.withContent(new String(Base64.getEncoder().encode(data)));
345 | attachment.withContentType("image/png");
346 |
347 | MessageCreateOptions options = new MessageCreateOptions();
348 | options.withTo(String.format("anything@%s", verifiedDomain))
349 | .withSend(true)
350 | .withSubject(subject)
351 | .withHtml("This is a new email.
")
352 | .withAttachments(Arrays.asList(new Attachment[] { attachment }));
353 |
354 | Message message = client.messages().create(server, options);
355 |
356 | assertEquals(1, message.attachments().size());
357 | Attachment file1 = message.attachments().get(0);
358 | assertNotNull(file1.id());
359 | assertEquals((Long) 82138L, file1.length());
360 | assertEquals("cat.png", file1.fileName());
361 | assertEquals("image/png", file1.contentType());
362 | }
363 |
364 | @Test
365 | public void testForwardText() throws IOException, MailosaurException {
366 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
367 |
368 | String body = "Forwarded message";
369 | String targetId = emails.get(0).id();
370 |
371 | MessageForwardOptions options = new MessageForwardOptions();
372 | options.withTo(String.format("anything@%s", verifiedDomain))
373 | .withText(body);
374 |
375 | Message message = client.messages().forward(targetId, options);
376 |
377 | assertNotNull(message.id());
378 | assertTrue(message.text().body().contains(body));
379 | }
380 |
381 | @Test
382 | public void testForwardHtml() throws IOException, MailosaurException {
383 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
384 |
385 | String body = "Forwarded HTML message.
";
386 | String targetId = emails.get(0).id();
387 |
388 | MessageForwardOptions options = new MessageForwardOptions();
389 | options.withTo(String.format("anything@%s", verifiedDomain))
390 | .withHtml(body);
391 |
392 | Message message = client.messages().forward(targetId, options);
393 |
394 | assertNotNull(message.id());
395 | assertTrue(message.html().body().contains(body));
396 | }
397 |
398 | @Test
399 | public void testForwardCc() throws IOException, MailosaurException {
400 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
401 |
402 | String body = "Forwarded HTML message.
";
403 | String targetId = emails.get(0).id();
404 | String ccRecipient = String.format("someoneelse@%s", verifiedDomain);
405 |
406 | MessageForwardOptions options = new MessageForwardOptions();
407 | options.withTo(String.format("forwardcc@%s", verifiedDomain))
408 | .withCc(ccRecipient)
409 | .withHtml(body);
410 |
411 | Message message = client.messages().forward(targetId, options);
412 |
413 | assertNotNull(message.id());
414 | assertTrue(message.html().body().contains(body));
415 | assertEquals(1, message.cc().size());
416 | assertEquals(ccRecipient, message.cc().get(0).email());
417 | }
418 |
419 | @Test
420 | public void testReplyText() throws IOException, MailosaurException {
421 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
422 |
423 | String body = "Reply message";
424 | String targetId = emails.get(0).id();
425 |
426 | MessageReplyOptions options = new MessageReplyOptions();
427 | options.withText(body);
428 |
429 | Message message = client.messages().reply(targetId, options);
430 |
431 | assertNotNull(message.id());
432 | assertTrue(message.text().body().contains(body));
433 | }
434 |
435 | @Test
436 | public void testReplyWithAttachment() throws IOException, MailosaurException {
437 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
438 |
439 | String body = "New reply with attachment";
440 | String targetId = emails.get(0).id();
441 |
442 | byte[] data = Files.readAllBytes(getResourceFilePath("cat.png"));
443 |
444 | Attachment attachment = new Attachment();
445 | attachment.withFileName("cat.png");
446 | attachment.withContent(new String(Base64.getEncoder().encode(data)));
447 | attachment.withContentType("image/png");
448 |
449 | MessageReplyOptions options = new MessageReplyOptions();
450 | options.withText(body)
451 | .withAttachments(Arrays.asList(new Attachment[] { attachment }));
452 |
453 | Message message = client.messages().reply(targetId, options);
454 |
455 | assertEquals(1, message.attachments().size());
456 | Attachment file1 = message.attachments().get(0);
457 | assertNotNull(file1.id());
458 | assertEquals((Long) 82138L, file1.length());
459 | assertEquals("cat.png", file1.fileName());
460 | assertEquals("image/png", file1.contentType());
461 | }
462 |
463 | @Test
464 | public void testReplyHtml() throws IOException, MailosaurException {
465 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
466 |
467 | String body = "Reply HTML message.
";
468 | String targetId = emails.get(0).id();
469 |
470 | MessageReplyOptions options = new MessageReplyOptions();
471 | options.withHtml(body);
472 |
473 | Message message = client.messages().reply(targetId, options);
474 |
475 | assertNotNull(message.id());
476 | assertTrue(message.html().body().contains(body));
477 | }
478 |
479 | @Test
480 | public void testReplyCc() throws IOException, MailosaurException {
481 | org.junit.Assume.assumeTrue(verifiedDomain != null && !verifiedDomain.isEmpty());
482 |
483 | String body = "Reply HTML message.
";
484 | String targetId = emails.get(0).id();
485 | String ccRecipient = String.format("someoneelse@%s", verifiedDomain);
486 | MessageReplyOptions options = new MessageReplyOptions();
487 | options.withCc(ccRecipient)
488 | .withHtml(body);
489 |
490 | Message message = client.messages().reply(targetId, options);
491 |
492 | assertNotNull(message.id());
493 | assertTrue(message.html().body().contains(body));
494 | assertEquals(1, message.cc().size());
495 | assertEquals(ccRecipient, message.cc().get(0).email());
496 | }
497 |
498 | private void validateEmail(Message email) {
499 | validateMetadata(email);
500 | validateAttachments(email);
501 | validateHtml(email);
502 | validateText(email);
503 | assertNotNull(email.metadata().mailFrom());
504 | assertEquals(1, email.metadata().rcptTo().size());
505 | assertNotNull(email.metadata().rcptTo());
506 | }
507 |
508 | private void validateEmailSummary(MessageSummary email) {
509 | validateMetadata(email);
510 | assertNotNull(email.summary());
511 | assertEquals(2, (int)email.attachments());
512 | }
513 |
514 | private void validateHtml(Message email) {
515 | // HTML.Body
516 | assertTrue(email.html().body().startsWith(""));
517 |
518 | // HTML.Links
519 | assertEquals(3, email.html().links().size());
520 | assertEquals("https://mailosaur.com/", email.html().links().get(0).href());
521 | assertEquals("mailosaur", email.html().links().get(0).text());
522 | assertEquals("https://mailosaur.com/", email.html().links().get(1).href());
523 | assertNull(email.html().links().get(1).text());
524 | assertEquals("http://invalid/", email.html().links().get(2).href());
525 | assertEquals("invalid", email.html().links().get(2).text());
526 |
527 | // HTML.Codes
528 | assertEquals(2, email.html().codes().size());
529 | assertEquals("123456", email.html().codes().get(0).value());
530 | assertEquals("G3H1Y2", email.html().codes().get(1).value());
531 |
532 | // HTML.Images
533 | assertTrue(email.html().images().get(1).src().startsWith("cid"));
534 | assertEquals("Inline image 1", email.html().images().get(1).alt());
535 | }
536 |
537 | private void validateText(Message email) {
538 | // Text.Body
539 | assertTrue(email.text().body().startsWith("this is a test"));
540 |
541 | // Text.Links
542 | assertEquals(2, email.text().links().size());
543 | assertEquals("https://mailosaur.com/", email.text().links().get(0).href());
544 | assertEquals(email.text().links().get(0).href(), email.text().links().get(0).text());
545 | assertEquals("https://mailosaur.com/", email.text().links().get(1).href());
546 | assertEquals(email.text().links().get(1).href(), email.text().links().get(1).text());
547 |
548 | // Text.Codes
549 | assertEquals(2, email.text().codes().size());
550 | assertEquals("654321", email.text().codes().get(0).value());
551 | assertEquals("5H0Y2", email.text().codes().get(1).value());
552 | }
553 |
554 | private void validateHeaders(Message email) {
555 | String expectedFromHeader = String.format("%s <%s>", email.from().get(0).name(), email.from().get(0).email());
556 | String expectedToHeader = String.format("%s <%s>", email.to().get(0).name(), email.to().get(0).email());
557 | List headers = email.metadata().headers();
558 | Stream fromHeader = headers.stream().filter(h -> h.field().toLowerCase().equals("from"));
559 | Stream toHeader = headers.stream().filter(h -> h.field().toLowerCase().equals("to"));
560 | Stream subjectHeader = headers.stream().filter(h -> h.field().toLowerCase().equals("subject"));
561 |
562 | // assertEquals(expectedFromHeader, fromHeader.findFirst().get());
563 | // assertEquals(expectedToHeader, toHeader.findFirst().get());
564 | // assertEquals(email.subject(), subjectHeader.findFirst().get());
565 | }
566 |
567 | private void validateMetadata(MessageSummary summary) {
568 | Message email = new Message(
569 | summary.type(),
570 | summary.from(),
571 | summary.to(),
572 | summary.subject(),
573 | summary.server(),
574 | summary.received()
575 | );
576 |
577 | validateMetadata(email);
578 | }
579 |
580 | private void validateMetadata(Message email) {
581 | assertEquals("Email", email.type());
582 | assertEquals(1, email.from().size());
583 | assertEquals(1, email.to().size());
584 | assertNotNull(email.from().get(0).email());
585 | assertNotNull(email.from().get(0).name());
586 | assertNotNull(email.to().get(0).email());
587 | assertNotNull(email.to().get(0).name());
588 | assertNotNull(email.subject());
589 | assertNotNull(email.server());
590 |
591 | assertTrue(email.received().toString().startsWith(isoDateString));
592 | }
593 |
594 | private void validateAttachments(Message email) {
595 | assertEquals(2, email.attachments().size());
596 |
597 | Attachment file1 = email.attachments().get(0);
598 | assertNotNull(file1.id());
599 | assertEquals((Long) 82138L, file1.length());
600 | assertEquals("cat.png", file1.fileName());
601 | assertEquals("image/png", file1.contentType());
602 |
603 | Attachment file2 = email.attachments().get(1);
604 | assertNotNull(file2.id());
605 | assertEquals((Long) 212080L, file2.length());
606 | assertEquals("dog.png", file2.fileName());
607 | assertEquals("image/png", file2.contentType());
608 | }
609 |
610 | private static Path getResourceFilePath(String relativePath) {
611 | String path = EmailsTest.class.getClassLoader().getResource(relativePath).getPath();
612 | return Paths.get(path);
613 | }
614 | }
615 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/ErrorsTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import com.mailosaur.models.*;
4 | import org.junit.BeforeClass;
5 | import org.junit.Test;
6 |
7 | import javax.mail.MessagingException;
8 | import java.io.IOException;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | public class ErrorsTest {
13 | private static String apiKey;
14 | private static String baseUrl;
15 |
16 | @BeforeClass
17 | public static void setUpBeforeClass() throws IOException {
18 | apiKey = System.getenv("MAILOSAUR_API_KEY");
19 | baseUrl = System.getenv("MAILOSAUR_BASE_URL");
20 |
21 | if (apiKey == null) {
22 | throw new IOException("Missing necessary environment variables - refer to README.md");
23 | }
24 | }
25 |
26 | @Test
27 | public void testUnauthorized() throws IOException {
28 | MailosaurClient client = new MailosaurClient("invalid_key", baseUrl);
29 | try {
30 | client.servers().list();
31 | } catch (MailosaurException ex) {
32 | assertEquals("com.mailosaur.MailosaurException: Authentication failed, check your API key.", ex.toString());
33 | }
34 | }
35 |
36 | @Test
37 | public void testNotFound() throws IOException {
38 | MailosaurClient client = new MailosaurClient(apiKey, baseUrl);
39 | try {
40 | client.servers().get("not_found");
41 | } catch (MailosaurException ex) {
42 | assertEquals("com.mailosaur.MailosaurException: Not found, check input parameters.", ex.toString());
43 | }
44 | }
45 |
46 | @Test
47 | public void testBadRequest() throws IOException {
48 | MailosaurClient client = new MailosaurClient(apiKey, baseUrl);
49 | try {
50 | ServerCreateOptions options = new ServerCreateOptions();
51 | client.servers().create(options);
52 | } catch (MailosaurException ex) {
53 | assertEquals("com.mailosaur.MailosaurException: (name) Servers need a name\r\n", ex.toString());
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/FilesTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertNotNull;
5 | import static org.junit.Assert.assertTrue;
6 |
7 | import java.io.IOException;
8 |
9 | import javax.mail.MessagingException;
10 |
11 | import com.mailosaur.models.MessageSearchParams;
12 | import org.junit.BeforeClass;
13 | import org.junit.Test;
14 |
15 | import com.mailosaur.models.Attachment;
16 | import com.mailosaur.models.Message;
17 | import com.mailosaur.models.SearchCriteria;
18 |
19 | public class FilesTest {
20 | private static MailosaurClient client;
21 | private static String server;
22 | private static Message email;
23 |
24 | @BeforeClass
25 | public static void setUpBeforeClass() throws IOException, MessagingException, MailosaurException {
26 | String baseUrl = System.getenv("MAILOSAUR_BASE_URL");
27 | String apiKey = System.getenv("MAILOSAUR_API_KEY");
28 | server = System.getenv("MAILOSAUR_SERVER");
29 |
30 | if (apiKey == null || server == null) {
31 | throw new IOException("Missing necessary environment variables - refer to README.md");
32 | }
33 |
34 | client = new MailosaurClient(apiKey, baseUrl);
35 |
36 | client.messages().deleteAll(server);
37 |
38 | String host = System.getenv("MAILOSAUR_SMTP_HOST");
39 | host = (host == null) ? "mailosaur.net" : host;
40 | String testEmailAddress = String.format("files_test@%s.%s", server, host);
41 |
42 | Mailer.sendEmail(client, server, testEmailAddress);
43 |
44 | MessageSearchParams params = new MessageSearchParams();
45 | params.withServer(server);
46 |
47 | SearchCriteria criteria = new SearchCriteria();
48 | criteria.withSentTo(testEmailAddress);
49 |
50 | email = client.messages().get(params, criteria);
51 | }
52 |
53 | @Test
54 | public void testGetEmail() throws IOException, MailosaurException {
55 | byte[] bytes = client.files().getEmail(email.id());
56 | assertNotNull(bytes);
57 | assertTrue(bytes.length > 1);
58 | assertTrue(new String(bytes).contains(email.subject()));
59 | }
60 |
61 | @Test
62 | public void testGetAttachment() throws IOException, MailosaurException {
63 | Attachment attachment = email.attachments().get(0);
64 | byte[] bytes = client.files().getAttachment(attachment.id());
65 |
66 | assertNotNull(bytes);
67 | assertEquals(attachment.length(), new Long(bytes.length));
68 | }
69 | }
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/Mailer.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import java.io.IOException;
4 | import java.io.UnsupportedEncodingException;
5 | import java.nio.file.Files;
6 | import java.nio.file.Path;
7 | import java.nio.file.Paths;
8 | import java.util.Properties;
9 | import java.util.Random;
10 |
11 | import javax.activation.DataHandler;
12 | import javax.activation.FileDataSource;
13 | import javax.mail.BodyPart;
14 | import javax.mail.MessagingException;
15 | import javax.mail.Multipart;
16 | import javax.mail.Session;
17 | import javax.mail.internet.InternetAddress;
18 | import javax.mail.internet.MimeBodyPart;
19 | import javax.mail.internet.MimeMessage;
20 | import javax.mail.internet.MimeMultipart;
21 |
22 | import com.mailosaur.MailosaurClient;
23 |
24 | public final class Mailer {
25 | private static Random random = new Random();
26 | private static String verifiedDomain;
27 | private static String html;
28 | private static String text;
29 |
30 | static {
31 | try {
32 | html = new String(Files.readAllBytes(getResourceFilePath("testEmail.html")), "utf-8");
33 | text = new String(Files.readAllBytes(getResourceFilePath("testEmail.txt")), "utf-8");
34 | verifiedDomain = System.getenv("MAILOSAUR_VERIFIED_DOMAIN");
35 | verifiedDomain = (verifiedDomain == null || verifiedDomain.length() == 0) ? "mailosaur.net" : verifiedDomain;
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | }
39 | }
40 |
41 | public static void sendEmails(MailosaurClient client, String server, int quantity) throws MessagingException {
42 | for (int i = 0; i < quantity; i++)
43 | sendEmail(client, server);
44 | }
45 |
46 | public static void sendEmail(MailosaurClient client, String server) throws MessagingException
47 | {
48 | sendEmail(client, server, null);
49 | }
50 |
51 | public static void sendEmail(MailosaurClient client, String server, String sendToAddress) throws MessagingException {
52 | String host = System.getenv("MAILOSAUR_SMTP_HOST");
53 | String port = System.getenv("MAILOSAUR_SMTP_PORT");
54 |
55 | Properties props = new Properties();
56 | props.put("mail.smtp.host", (host == null) ? "mailosaur.net" : host);
57 | props.put("mail.smtp.port", (port == null) ? "25" : port);
58 | props.put("mail.smtp.auth", "false");
59 | props.put("mail.smtp.starttls.enable", "false");
60 |
61 | Session session = Session.getInstance(props);
62 | MimeMessage message = new MimeMessage(session);
63 |
64 | String randomString = getRandomString(10);
65 |
66 | message.setSubject(String.format("%s subject", randomString));
67 |
68 | message.setFrom(new InternetAddress(String.format("%s %s <%s@%s>", randomString, randomString,
69 | randomString, verifiedDomain)));
70 |
71 | String randomToAddress = (sendToAddress == null) ? client.servers().generateEmailAddress(server) : sendToAddress;
72 |
73 | message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(String.format("%s %s <%s>", randomString, randomString,
74 | randomToAddress)));
75 |
76 | Multipart alternative = new MimeMultipart("alternative");
77 |
78 | // Text body
79 | MimeBodyPart textPart = new MimeBodyPart();
80 | textPart.setContent(text.replace("REPLACED_DURING_TEST", randomString), "text/plain");
81 | alternative.addBodyPart(textPart);
82 |
83 | // HTML body
84 | MimeBodyPart htmlPart = new MimeBodyPart();
85 | htmlPart.setContent(html.replace("REPLACED_DURING_TEST", randomString), "text/html");
86 | alternative.addBodyPart(htmlPart);
87 |
88 | BodyPart imagePart = new MimeBodyPart();
89 | imagePart.setDataHandler(new DataHandler(new FileDataSource(getResourceFilePath("cat.png").toString())));
90 | imagePart.setHeader("content-type", "image/png");
91 | imagePart.setHeader("Content-ID", "ii_1435fadb31d523f6");
92 | imagePart.setFileName("cat.png");
93 | alternative.addBodyPart(imagePart);
94 |
95 | BodyPart attachmentPart = new MimeBodyPart();
96 | attachmentPart.setDataHandler(new DataHandler(new FileDataSource(getResourceFilePath("dog.png").toString())));
97 | attachmentPart.setHeader("content-type", "image/png");
98 | attachmentPart.setFileName("dog.png");
99 | alternative.addBodyPart(attachmentPart);
100 |
101 | message.setContent(alternative);
102 |
103 | session.getTransport("smtp").send(message);
104 | }
105 |
106 | private static Path getResourceFilePath(String relativePath) {
107 | String path = Mailer.class.getClassLoader().getResource(relativePath).getPath();
108 | return Paths.get(path);
109 | }
110 |
111 | public static String getRandomString(int length) {
112 | int leftLimit = 97; // letter 'a'
113 | int rightLimit = 122; // letter 'z'
114 | Random random = new Random();
115 |
116 | String generatedString = random.ints(leftLimit, rightLimit + 1)
117 | .limit(length)
118 | .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
119 | .toString();
120 |
121 | return generatedString;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/PreviewsTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import com.mailosaur.models.*;
4 | import org.junit.BeforeClass;
5 | import org.junit.Test;
6 |
7 | import javax.mail.MessagingException;
8 | import java.io.IOException;
9 | import java.util.Arrays;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | public class PreviewsTest {
14 | private static MailosaurClient client;
15 | private static String server;
16 |
17 | @BeforeClass
18 | public static void setUpBeforeClass() throws IOException {
19 | String baseUrl = System.getenv("MAILOSAUR_BASE_URL");
20 | String apiKey = System.getenv("MAILOSAUR_API_KEY");
21 | server = System.getenv("MAILOSAUR_PREVIEWS_SERVER");
22 |
23 | if (apiKey == null) {
24 | throw new IOException("Missing necessary environment variables - refer to README.md");
25 | }
26 |
27 | client = new MailosaurClient(apiKey, baseUrl);
28 | }
29 |
30 | @Test
31 | public void testListEmailClients() throws IOException, MailosaurException {
32 | PreviewEmailClientListResult result = client.previews().listEmailClients();
33 | assertTrue(result.items().size() > 1);
34 | }
35 |
36 | @Test
37 | public void testGeneratePreviews() throws IOException, MailosaurException, MessagingException {
38 | org.junit.Assume.assumeTrue(server != null && !server.isEmpty());
39 |
40 | String randomString = Mailer.getRandomString(7);
41 | String host = System.getenv("MAILOSAUR_SMTP_HOST");
42 | host = (host == null) ? "mailosaur.net" : host;
43 |
44 | String testEmailAddress = String.format("%s@%s.%s", randomString, server, host);
45 |
46 | Mailer.sendEmail(client, server, testEmailAddress);
47 |
48 | SearchCriteria criteria = new SearchCriteria();
49 | criteria.withSentTo(testEmailAddress);
50 |
51 | MessageSearchParams params = new MessageSearchParams();
52 | params.withServer(server);
53 | Message email = client.messages().get(params, criteria);
54 |
55 | PreviewRequest request = new PreviewRequest("OL2021");
56 | PreviewRequestOptions options = new PreviewRequestOptions();
57 | options.withPreviews(Arrays.asList(request));
58 |
59 | PreviewListResult result = client.messages().generatePreviews(email.id(), options);
60 | assertTrue(result.items().size() > 0);
61 |
62 | // Ensure we can download one of the generated preview
63 | byte[] bytes = client.files().getPreview(result.items().get(0).id());
64 | assertNotNull(bytes);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/ServersTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.io.IOException;
6 |
7 | import javax.mail.MessagingException;
8 |
9 | import org.junit.BeforeClass;
10 | import org.junit.Test;
11 |
12 | import com.mailosaur.models.Server;
13 | import com.mailosaur.models.ServerCreateOptions;
14 | import com.mailosaur.models.ServerListResult;
15 |
16 | public class ServersTest {
17 | private static MailosaurClient client;
18 |
19 | @BeforeClass
20 | public static void setUpBeforeClass() throws IOException {
21 | String apiKey = System.getenv("MAILOSAUR_API_KEY");
22 | String baseUrl = System.getenv("MAILOSAUR_BASE_URL");
23 |
24 | if (apiKey == null) {
25 | throw new IOException("Missing necessary environment variables - refer to README.md");
26 | }
27 |
28 | client = new MailosaurClient(apiKey, baseUrl);
29 | }
30 |
31 | @Test
32 | public void testList() throws IOException, MailosaurException {
33 | ServerListResult servers = client.servers().list();
34 | assertTrue(servers.items().size() > 1);
35 | }
36 |
37 | @Test(expected = MailosaurException.class)
38 | public void testGetNotFound() throws IOException, MailosaurException {
39 | client.servers().get("efe907e9-74ed-4113-a3e0-a3d41d914765");
40 | }
41 |
42 | @Test
43 | public void testCrud() throws IOException, MailosaurException {
44 | String serverName = "My test";
45 |
46 | // Create a new server
47 | ServerCreateOptions options = new ServerCreateOptions().withName(serverName);
48 | Server createdServer = client.servers().create(options);
49 | assertNotNull(createdServer.id());
50 | assertNotNull(createdServer.users());
51 | assertEquals(0, (int)createdServer.messages());
52 |
53 | // Retrieve a server and confirm it has expected content
54 | Server retrievedServer = client.servers().get(createdServer.id());
55 | assertEquals(createdServer.id(), retrievedServer.id());
56 | assertEquals(createdServer.name(), retrievedServer.name());
57 | assertNotNull(retrievedServer.users());
58 | assertEquals(0, (int)retrievedServer.messages());
59 |
60 | // Retrieve server password
61 | String password = client.servers().getPassword(createdServer.id());
62 | assertTrue(password.length() >= 8);
63 |
64 | // Update a server and confirm it has changed
65 | retrievedServer.withName(serverName += " updated with ellipsis … and emoji 👨🏿🚒");
66 | Server updatedServer = client.servers().update(retrievedServer.id(), retrievedServer);
67 | assertEquals(retrievedServer.id(), updatedServer.id());
68 | assertEquals(retrievedServer.name(), updatedServer.name());
69 | assertEquals(retrievedServer.users(), updatedServer.users());
70 | assertEquals(retrievedServer.messages(), updatedServer.messages());
71 |
72 | client.servers().delete(retrievedServer.id());
73 |
74 | // Attempting to delete again should fail
75 | try {
76 | client.servers().delete(retrievedServer.id());
77 | throw new IOException("Should have thrown MailosaurException");
78 | } catch (MailosaurException e) { }
79 | }
80 |
81 | @Test
82 | public void testFailedCreate() throws IOException {
83 | ServerCreateOptions options = new ServerCreateOptions();
84 |
85 | try {
86 | client.servers().create(options);
87 | throw new IOException("Should have thrown MailosaurException");
88 | } catch (MailosaurException e) {
89 | assertEquals("(name) Servers need a name\r\n", e.getMessage());
90 | assertEquals("invalid_request", e.errorType());
91 | assertEquals(Integer.valueOf(400), e.httpStatusCode());
92 | assertTrue(e.httpResponseBody().contains("{\"type\":"));
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/test/java/com/mailosaur/UsageTest.java:
--------------------------------------------------------------------------------
1 | package com.mailosaur;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.io.IOException;
6 |
7 | import javax.mail.MessagingException;
8 |
9 | import org.junit.BeforeClass;
10 | import org.junit.Test;
11 |
12 | import com.mailosaur.models.UsageAccountLimits;
13 | import com.mailosaur.models.UsageTransactionListResult;
14 |
15 | public class UsageTest {
16 | private static MailosaurClient client;
17 |
18 | @BeforeClass
19 | public static void setUpBeforeClass() throws IOException {
20 | String apiKey = System.getenv("MAILOSAUR_API_KEY");
21 | String baseUrl = System.getenv("MAILOSAUR_BASE_URL");
22 |
23 | if (apiKey == null) {
24 | throw new IOException("Missing necessary environment variables - refer to README.md");
25 | }
26 |
27 | client = new MailosaurClient(apiKey, baseUrl);
28 | }
29 |
30 | @Test
31 | public void testLimits() throws IOException, MailosaurException {
32 | UsageAccountLimits result = client.usage().limits();
33 | assertNotNull(result.servers());
34 | assertNotNull(result.users());
35 | assertNotNull(result.email());
36 | assertNotNull(result.sms());
37 |
38 | assertTrue(result.servers().limit() > 0);
39 | assertTrue(result.users().limit() > 0);
40 | assertTrue(result.email().limit() > 0);
41 | assertTrue(result.sms().limit() > 0);
42 | }
43 |
44 | @Test
45 | public void testTransactions() throws IOException, MailosaurException {
46 | UsageTransactionListResult result = client.usage().transactions();
47 | assertTrue(result.items().size() > 1);
48 | assertNotNull(result.items().get(0).timestamp());
49 | assertNotNull(result.items().get(0).email());
50 | assertNotNull(result.items().get(0).sms());
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/test/resources/cat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mailosaur/mailosaur-java/3d371fa9b684a307ca5f4fc6aae9b7cecab519e0/src/test/resources/cat.png
--------------------------------------------------------------------------------
/src/test/resources/dog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mailosaur/mailosaur-java/3d371fa9b684a307ca5f4fc6aae9b7cecab519e0/src/test/resources/dog.png
--------------------------------------------------------------------------------
/src/test/resources/testEmail.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | this is a test.
4 |
9 |
36 |
37 |
--------------------------------------------------------------------------------
/src/test/resources/testEmail.txt:
--------------------------------------------------------------------------------
1 | this is a test.
2 |
3 | this is a link: mailosaur
4 |
5 | REPLACED_DURING_TEST text
6 |
7 | this is an image:[image: Inline image 1]
8 |
9 | Your verification code is 654321
10 |
11 | Your special ID is 5H0Y2
12 |
13 | this is an invalid link: invalid
14 |
--------------------------------------------------------------------------------
/src/test/test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------