forked from pooranjoyb/cpp-sdk-appwrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateEmail.cpp
More file actions
49 lines (40 loc) · 1.6 KB
/
createEmail.cpp
File metadata and controls
49 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Appwrite.hpp"
#include <chrono>
#include <iostream>
int main() {
std::string projectId = "";
std::string apiKey = "";
Appwrite appwrite(projectId, apiKey);
std::string messageId = "email001";
std::string subject = "Hello from C++ Appwrite SDK!";
std::string content =
"Testing Email message creation with topics, users, and targets.";
std::vector<std::string> topics = {};
std::vector<std::string> users = {};
std::vector<std::string> targets = {};
std::vector<std::string> cc = {};
std::vector<std::string> bcc = {};
std::vector<std::string> attachments = {};
auto now = std::chrono::system_clock::now();
auto future_time = now + std::chrono::minutes(5);
auto time_t = std::chrono::system_clock::to_time_t(future_time);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
future_time.time_since_epoch()) %
1000;
std::stringstream ss;
ss << std::put_time(std::gmtime(&time_t), "%Y-%m-%dT%H:%M:%S");
ss << "." << std::setfill('0') << std::setw(3) << ms.count() << "+00:00";
std::string scheduled_at = ss.str();
bool draft = true;
bool html = false;
try {
std::string response = appwrite.getMessaging().createEmail(
messageId, subject, content, topics, users, targets, cc, bcc,
attachments, draft, html, scheduled_at);
std::cout << "Email Message Created!\nResponse: " << response
<< std::endl;
} catch (const AppwriteException &ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
}
return 0;
}