Skip to content

Commit 464efd7

Browse files
feat: Inbound emails (beta) (#65)
Co-authored-by: Lucas Fernandes da Costa <[email protected]>
1 parent 1ea3155 commit 464efd7

File tree

15 files changed

+1957
-0
lines changed

15 files changed

+1957
-0
lines changed

src/main/java/com/resend/Resend.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.resend.services.contacts.Contacts;
88
import com.resend.services.domains.Domains;
99
import com.resend.services.emails.Emails;
10+
import com.resend.services.receiving.Receiving;
1011
import com.resend.services.topics.Topics;
1112
import com.resend.services.templates.Templates;
1213

@@ -92,6 +93,15 @@ public Broadcasts broadcasts() {
9293
return new Broadcasts(apiKey);
9394
}
9495

96+
/**
97+
* Returns a Receiving object that can be used to interact with the Receiving service for inbound emails.
98+
*
99+
* @return A Receiving object.
100+
*/
101+
public Receiving receiving() {
102+
return new Receiving(apiKey);
103+
}
104+
95105
/**
96106
* Returns a Topics object that can be used to interact with the Topics service.
97107
*

src/main/java/com/resend/services/emails/Emails.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,82 @@ public ListEmailsResponseSuccess list(ListParams params) throws ResendException
192192

193193
return resendMapper.readValue(responseBody, ListEmailsResponseSuccess.class);
194194
}
195+
196+
/**
197+
* Retrieves a single attachment from a sent email.
198+
*
199+
* @param emailId The unique identifier of the email.
200+
* @param attachmentId The unique identifier of the attachment.
201+
* @return The attachment details including download URL.
202+
* @throws ResendException If an error occurs while retrieving the attachment.
203+
*/
204+
public AttachmentResponse getAttachment(String emailId, String attachmentId) throws ResendException {
205+
AbstractHttpResponse<String> response = this.httpClient.perform(
206+
"/emails/" + emailId + "/attachments/" + attachmentId,
207+
super.apiKey,
208+
HttpMethod.GET,
209+
null,
210+
MediaType.get("application/json")
211+
);
212+
213+
if (!response.isSuccessful()) {
214+
throw new ResendException(response.getCode(), response.getBody());
215+
}
216+
217+
String responseBody = response.getBody();
218+
219+
return resendMapper.readValue(responseBody, AttachmentResponse.class);
220+
}
221+
222+
/**
223+
* Retrieves all attachments from a sent email.
224+
*
225+
* @param emailId The unique identifier of the email.
226+
* @return A ListAttachmentsResponse containing all attachments from the email.
227+
* @throws ResendException If an error occurs while retrieving the attachments.
228+
*/
229+
public ListAttachmentsResponse listAttachments(String emailId) throws ResendException {
230+
AbstractHttpResponse<String> response = this.httpClient.perform(
231+
"/emails/" + emailId + "/attachments",
232+
super.apiKey,
233+
HttpMethod.GET,
234+
null,
235+
MediaType.get("application/json")
236+
);
237+
238+
if (!response.isSuccessful()) {
239+
throw new ResendException(response.getCode(), response.getBody());
240+
}
241+
242+
String responseBody = response.getBody();
243+
244+
return resendMapper.readValue(responseBody, ListAttachmentsResponse.class);
245+
}
246+
247+
/**
248+
* Retrieves a paginated list of attachments from a sent email.
249+
*
250+
* @param emailId The unique identifier of the email.
251+
* @param params The params used to customize the list (pagination).
252+
* @return A ListAttachmentsResponse containing the paginated list of attachments.
253+
* @throws ResendException If an error occurs while retrieving the attachments.
254+
*/
255+
public ListAttachmentsResponse listAttachments(String emailId, ListParams params) throws ResendException {
256+
String pathWithQuery = "/emails/" + emailId + "/attachments" + URLHelper.parse(params);
257+
AbstractHttpResponse<String> response = this.httpClient.perform(
258+
pathWithQuery,
259+
super.apiKey,
260+
HttpMethod.GET,
261+
null,
262+
MediaType.get("application/json")
263+
);
264+
265+
if (!response.isSuccessful()) {
266+
throw new ResendException(response.getCode(), response.getBody());
267+
}
268+
269+
String responseBody = response.getBody();
270+
271+
return resendMapper.readValue(responseBody, ListAttachmentsResponse.class);
272+
}
195273
}
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
package com.resend.services.emails.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* Represents the response when retrieving an attachment from a sent email.
7+
*/
8+
public class AttachmentResponse {
9+
10+
/**
11+
* The object type, always "attachment".
12+
*/
13+
@JsonProperty("object")
14+
private String object;
15+
16+
/**
17+
* The unique identifier of the attachment.
18+
*/
19+
@JsonProperty("id")
20+
private String id;
21+
22+
/**
23+
* The filename of the attachment.
24+
*/
25+
@JsonProperty("filename")
26+
private String filename;
27+
28+
/**
29+
* The size of the attachment in bytes.
30+
*/
31+
@JsonProperty("size")
32+
private Integer size;
33+
34+
/**
35+
* The MIME content type of the attachment.
36+
*/
37+
@JsonProperty("content_type")
38+
private String contentType;
39+
40+
/**
41+
* The content disposition (inline or attachment).
42+
*/
43+
@JsonProperty("content_disposition")
44+
private String contentDisposition;
45+
46+
/**
47+
* The content ID for inline attachments.
48+
*/
49+
@JsonProperty("content_id")
50+
private String contentId;
51+
52+
/**
53+
* The download URL for the attachment.
54+
*/
55+
@JsonProperty("download_url")
56+
private String downloadUrl;
57+
58+
/**
59+
* The expiration timestamp of the download URL.
60+
*/
61+
@JsonProperty("expires_at")
62+
private String expiresAt;
63+
64+
/**
65+
* Get the object type.
66+
* @return The object type.
67+
*/
68+
public String getObject() {
69+
return object;
70+
}
71+
72+
/**
73+
* Set the object type.
74+
* @param object The object type.
75+
*/
76+
public void setObject(String object) {
77+
this.object = object;
78+
}
79+
80+
/**
81+
* Get the attachment ID.
82+
* @return The attachment ID.
83+
*/
84+
public String getId() {
85+
return id;
86+
}
87+
88+
/**
89+
* Set the attachment ID.
90+
* @param id The attachment ID.
91+
*/
92+
public void setId(String id) {
93+
this.id = id;
94+
}
95+
96+
/**
97+
* Get the filename.
98+
* @return The filename.
99+
*/
100+
public String getFilename() {
101+
return filename;
102+
}
103+
104+
/**
105+
* Set the filename.
106+
* @param filename The filename.
107+
*/
108+
public void setFilename(String filename) {
109+
this.filename = filename;
110+
}
111+
112+
/**
113+
* Get the size in bytes.
114+
* @return The size.
115+
*/
116+
public Integer getSize() {
117+
return size;
118+
}
119+
120+
/**
121+
* Set the size.
122+
* @param size The size in bytes.
123+
*/
124+
public void setSize(Integer size) {
125+
this.size = size;
126+
}
127+
128+
/**
129+
* Get the content type.
130+
* @return The content type.
131+
*/
132+
public String getContentType() {
133+
return contentType;
134+
}
135+
136+
/**
137+
* Set the content type.
138+
* @param contentType The content type.
139+
*/
140+
public void setContentType(String contentType) {
141+
this.contentType = contentType;
142+
}
143+
144+
/**
145+
* Get the content disposition.
146+
* @return The content disposition.
147+
*/
148+
public String getContentDisposition() {
149+
return contentDisposition;
150+
}
151+
152+
/**
153+
* Set the content disposition.
154+
* @param contentDisposition The content disposition.
155+
*/
156+
public void setContentDisposition(String contentDisposition) {
157+
this.contentDisposition = contentDisposition;
158+
}
159+
160+
/**
161+
* Get the content ID.
162+
* @return The content ID.
163+
*/
164+
public String getContentId() {
165+
return contentId;
166+
}
167+
168+
/**
169+
* Set the content ID.
170+
* @param contentId The content ID.
171+
*/
172+
public void setContentId(String contentId) {
173+
this.contentId = contentId;
174+
}
175+
176+
/**
177+
* Get the download URL.
178+
* @return The download URL.
179+
*/
180+
public String getDownloadUrl() {
181+
return downloadUrl;
182+
}
183+
184+
/**
185+
* Set the download URL.
186+
* @param downloadUrl The download URL.
187+
*/
188+
public void setDownloadUrl(String downloadUrl) {
189+
this.downloadUrl = downloadUrl;
190+
}
191+
192+
/**
193+
* Get the expiration timestamp.
194+
* @return The expiration timestamp.
195+
*/
196+
public String getExpiresAt() {
197+
return expiresAt;
198+
}
199+
200+
/**
201+
* Set the expiration timestamp.
202+
* @param expiresAt The expiration timestamp.
203+
*/
204+
public void setExpiresAt(String expiresAt) {
205+
this.expiresAt = expiresAt;
206+
}
207+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.resend.services.emails.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.util.List;
5+
6+
/**
7+
* Represents a successful response for listing attachments.
8+
*/
9+
public class ListAttachmentsResponse {
10+
11+
@JsonProperty("object")
12+
private String object;
13+
14+
@JsonProperty("data")
15+
private List<AttachmentResponse> data;
16+
17+
@JsonProperty("has_more")
18+
private Boolean hasMore;
19+
20+
/**
21+
* Default constructor
22+
*/
23+
public ListAttachmentsResponse() {
24+
}
25+
26+
/**
27+
* Constructs a successful response for listing attachments.
28+
*
29+
* @param data The list of attachments.
30+
* @param object The object type, always "list".
31+
* @param hasMore Whether there are more attachments available for pagination.
32+
*/
33+
public ListAttachmentsResponse(final List<AttachmentResponse> data, final String object, final Boolean hasMore) {
34+
this.data = data;
35+
this.object = object;
36+
this.hasMore = hasMore;
37+
}
38+
39+
/**
40+
* Gets the list of attachments.
41+
*
42+
* @return The list of attachments.
43+
*/
44+
public List<AttachmentResponse> getData() {
45+
return data;
46+
}
47+
48+
/**
49+
* Gets the object type.
50+
*
51+
* @return The object type.
52+
*/
53+
public String getObject() {
54+
return object;
55+
}
56+
57+
/**
58+
* Gets the indicator whether there are more items available for pagination.
59+
*
60+
* @return Whether there are more items available for pagination.
61+
*/
62+
public Boolean hasMore() {
63+
return hasMore;
64+
}
65+
}

0 commit comments

Comments
 (0)