Skip to content

Commit e519207

Browse files
Update Email
1 parent b3b6b40 commit e519207

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp
273273
listTargets: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp
274274
@mkdir -p ./$(TESTS_DIR)
275275
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/listTargets $(SRCS) $(EXAMPLES_DIR)/messaging/messages/listTargets.cpp $(LDFLAGS)
276+
updateEmail: $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp
277+
@mkdir -p ./$(TESTS_DIR)
278+
$(CXX) $(CXXFLAGS) -o ./$(TESTS_DIR)/updateEmail $(SRCS) $(EXAMPLES_DIR)/messaging/messages/updateEmail.cpp $(LDFLAGS)
276279

277280
# Messaging - Topics
278281
getTopic: $(SRCS) $(EXAMPLES_DIR)/messaging/topics/getTopic.cpp

include/classes/Messaging.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,26 @@ class Messaging {
155155
const std::string& content,
156156
const std::vector<std::string>& topics = {},
157157
const std::vector<std::string>& targets = {});
158-
158+
/**
159+
* @brief Update an email message by its ID.
160+
* @class updateEmail
161+
*
162+
* This method belongs to the updateEmail class and provides the functionality
163+
* to update the subject and content of an existing email message via the
164+
* Appwrite Messaging API.
165+
*
166+
* @param messageId Unique message identifier
167+
* @param subject New subject of the email
168+
* @param content Updated content/body of the email
169+
* @return JSON response string from the server
170+
* @throws AppwriteException if parameters are invalid or request fails
171+
*/
172+
std::string updateEmail(
173+
const std::string& messageId,
174+
const std::string& subject,
175+
const std::string& content
176+
);
177+
159178
/**
160179
* @brief Updates an existing push notification message.
161180
*

src/services/Messaging.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,41 @@ std::string Messaging::createMessage(const std::string& messageId,
468468
}
469469
}
470470

471+
std::string Messaging::updateEmail(
472+
const std::string& messageId,
473+
const std::string& subject,
474+
const std::string& content
475+
) {
476+
if (messageId.empty()) {
477+
throw AppwriteException("Missing required parameter: 'messageId'");
478+
}
479+
if (subject.empty()) {
480+
throw AppwriteException("Missing required parameter: 'subject'");
481+
}
482+
if (content.empty()) {
483+
throw AppwriteException("Missing required parameter: 'content'");
484+
}
485+
486+
std::string url = Config::API_BASE_URL + "/messaging/messages/email/" + Utils::urlEncode(messageId);
487+
488+
std::string payload = R"({"subject":")" + Utils::escapeJsonString(subject) +
489+
R"(","content":")" + Utils::escapeJsonString(content) + R"("})";
490+
491+
std::vector<std::string> headers = Config::getHeaders(projectId);
492+
headers.push_back("X-Appwrite-Key: " + apiKey);
493+
headers.push_back("Content-Type: application/json");
494+
495+
std::string response;
496+
int statusCode = Utils::patchRequest(url, payload, headers, response);
497+
498+
if (statusCode == HttpStatus::OK) {
499+
return response;
500+
} else {
501+
throw AppwriteException("Error updating message. Status code: " + std::to_string(statusCode) +
502+
"\n\nResponse: " + response);
503+
}
504+
}
505+
471506
std::string Messaging::updatePush(const std::string &messageId,
472507
const std::string &title,
473508
const std::string &body,

0 commit comments

Comments
 (0)