| 193 | Example of sending an email from an app: |
| 194 | |
| 195 | {{{ |
| 196 | void TestSendEmail(const char* from, const char* to, const char* subject) |
| 197 | { |
| 198 | FILE* file = fopen("/tmp/emailmsg.txt", "w"); |
| 199 | if(file != NULL) { |
| 200 | fprintf(file, "From: %s\n", from); |
| 201 | fprintf(file, "To: %s\n", to); |
| 202 | fprintf(file, "Subject: %s\n", subject); |
| 203 | fprintf(file, "MIME-Version: 1.0\n"); |
| 204 | fprintf(file, "Content-Type: multipart/mixed; boundary=\"MyBoundaryString\""); |
| 205 | fprintf(file, "\n"); |
| 206 | fprintf(file, "\n"); |
| 207 | fprintf(file, "--MyBoundaryString\n"); |
| 208 | fprintf(file, "Content-Type: text/plain\n"); |
| 209 | fprintf(file, "Content-Transfer-Encoding: 7bit\n"); |
| 210 | fprintf(file, "\n"); |
| 211 | fprintf(file, "\n"); |
| 212 | fprintf(file, "Transaction %d\n", tran.tktNum); |
| 213 | fprintf(file, "\n"); |
| 214 | fprintf(file, "Out: %s %s\n", tran.date.c_str(), tran.time.c_str()); |
| 215 | fprintf(file, "In: %s %s\n", tran.inDate.c_str(), tran.inTime.c_str()); |
| 216 | fprintf(file, "\n"); |
| 217 | fprintf(file, "Truck: %s\n", tran.id[DB_TRUCK].c_str()); |
| 218 | fprintf(file, "Product: %s\n", tran.id[DB_PROD].c_str()); |
| 219 | fprintf(file, "Customer: %s\n", tran.id[DB_CUST].c_str()); |
| 220 | fprintf(file, "Job: %s\n", tran.id[DB_JOB].c_str()); |
| 221 | fprintf(file, "\n"); |
| 222 | fprintf(file, "Gross: %s\n", tran.gross.c_str()); |
| 223 | fprintf(file, "Tare: %s\n", tran.tare.c_str()); |
| 224 | fprintf(file, "Net: %s\n", tran.net.c_str()); |
| 225 | fprintf(file, "\n"); |
| 226 | fprintf(file, "--MyBoundaryString\n"); |
| 227 | fprintf(file, "Content-Type: image/jpeg\n"); |
| 228 | fprintf(file, "Content-ID: <image11>\n"); |
| 229 | fprintf(file, "Content-Transfer-Encoding: base64\n"); |
| 230 | fprintf(file, "\n"); |
| 231 | |
| 232 | fclose(file); |
| 233 | |
| 234 | // Convert second pass image into base64 |
| 235 | char tmp[128]; |
| 236 | sprintf_s(tmp, "base64 /usr/share/apache2/default-site/htdocs/images/v%06d_1.jpg > /tmp/attachment", tran.tktNum); |
| 237 | if(system(tmp) != 0) { |
| 238 | DEBUG_MSG("Error encoding jpg into base64 [%s]\n", tmp); |
| 239 | } else { |
| 240 | // Send it |
| 241 | if(system("cat /tmp/emailmsg.txt /tmp/attachment | msmtp -t") != 0) { |
| 242 | DEBUG_MSG("Error sending\n"); |
| 243 | } |
| 244 | |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | }}} |
| 249 | |
| 250 | When transaction is completed app can call this function such as: |
| 251 | {{{ |
| 252 | char msg[80]; |
| 253 | sprintf_s(msg, "ID Storage transaction %d", tran.tktNum); |
| 254 | TestSendEmail("myaccount@gmail.com", "someone@gmail.com", msg); |
| 255 | }}} |
| 256 | |