1 #ifndef RAPP_CLOUD_EMAIL
2 #define RAPP_CLOUD_EMAIL
29 const std::string email,
30 const std::string pwd,
31 const std::string server,
32 const std::string
port,
33 const std::string email_status,
34 const unsigned int from_date,
35 const unsigned int to_date,
36 const unsigned int num_emails,
37 const std::string token,
38 std::function<
void(std::string)> callback
42 boost::property_tree::ptree tree;
43 tree.put(
"email", email);
44 tree.put(
"passwd", pwd);
45 tree.put(
"server", server);
46 tree.put(
"port", port);
47 tree.put(
"email_status", email_status);
48 tree.put(
"from_date", boost::lexical_cast<std::string>(from_date));
49 tree.put(
"to_date", boost::lexical_cast<std::string>(to_date));
50 tree.put(
"num_emails", boost::lexical_cast<std::string>(num_emails));
52 boost::property_tree::write_json(ss, tree,
false);
54 header_ =
"POST /hop/email_fetch HTTP/1.1\r\n"
55 +
"Content-Type: application/x-www-form-urlencoded\r\n";
65 std::stringstream ss(json);
96 const std::string email,
97 const std::string pwd,
98 const std::string server,
99 const std::string
port,
100 const std::vector<std::string> recipients,
101 const std::string body,
102 const std::string subject,
103 const std::vector<rapp::types::byte> data,
104 const std::string token,
105 std::function<
void(std::string)> callback
111 boost::property_tree::ptree tree;
112 tree.put(
"email", email);
113 tree.put(
"passwd", pwd);
114 tree.put(
"server", server);
115 tree.put(
"port", port);
116 tree.put(
"body", body);
117 tree.put(
"subject", subject);
118 boost::property_tree::ptree array;
119 for (
const auto rec : recipients) {
120 array.push_back(std::make_pair(
"", rec));
122 tree.add_child(
"recipients", array);
123 tree.put(
"file", fname);
124 std::stringstream ss;
125 boost::property_tree::write_json(ss, tree,
false);
126 post_ =
"--" + boundary +
"\r\n"
127 +
"Content-Disposition: form-data; name=\"json\"\r\n\r\n"
130 post_ +=
"--" + boundary +
"\r\n"
131 +
"Content-Disposition: form-data; name=\"file_uri\"; filename\"" + fname +
"\"\r\n"
132 +
"Content-Transfer-Encoding: binary\r\n\r\n";
133 post_.insert(
post_.end(), data.begin(), data.end());
134 post_ +=
"\r\n--" + boundary +
"--";
136 header_ =
"POST /hop/email_send HTTP/1.1\r\n";
137 +
"Content-Type: multipart/form-data; boundary=" + boundary +
"\r\n\r\n";
147 std::stringstream ss(json);
std::string header_
Header that will be used.
void handle_reply(std::string json)
handle platform's JSON reply
std::string random_boundary() const
Create a random boundary for the multipart/form in HTTP.
std::function< void(std::string)> delegate_
constexpr char port[]
api.rapp.cloud - HOP server port
std::string post_
Actual post Data.
email_send(const std::string email, const std::string pwd, const std::string server, const std::string port, const std::vector< std::string > recipients, const std::string body, const std::string subject, const std::vector< rapp::types::byte > data, const std::string token, std::function< void(std::string)> callback)
construct in order to send email
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
void handle_reply(std::string json)
handle platform's JSON reply
std::function< void(std::string)> delegate_
email_fetch(const std::string email, const std::string pwd, const std::string server, const std::string port, const std::string email_status, const unsigned int from_date, const unsigned int to_date, const unsigned int num_emails, const std::string token, std::function< void(std::string)> callback)
construct in order to acquire email(s)
base class for asynchronous http websockets used for connecting to cloud services ...