UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / win32 / email.c
blob18d4b5ff5a18d36cf9f54802de0e8e151505bc66
1 /*
2 * Dumb program to send an email message
4 * Called:
5 * email -s "Subject" address@somewhere.com -m "Body of text"
7 * Kern Sibbald, October MM
8 */
10 #include <windows.h>
11 #include <mapi.h>
12 #include <stdio.h>
14 #ifndef HAVE_MINGW
15 extern void mainCRTStartup();
16 void WinMainCRTStartup() { mainCRTStartup(); }
17 #endif
19 int main(int argc, char **argv)
21 int i;
22 ULONG err;
23 MapiRecipDesc recip;
24 char addr[100];
25 MapiMessage emsg = {0,
26 "Apcupsd message", /* default subject */
27 "No text specified.\n", /* default message text */
28 NULL, NULL, NULL, 0, NULL,
29 1, &recip, 0, NULL};
31 recip.ulReserved = 0;
32 recip.ulRecipClass = MAPI_TO;
33 recip.lpszName = "root"; /* default name */
34 recip.lpszAddress = "SMTP:root"; /* default address */
35 recip.ulEIDSize = 0;
36 recip.lpEntryID = NULL;
38 for (i=1; i<argc; i++) {
39 if (strcmp(argv[i], "-s") == 0) { /* Subject */
40 if (++i < argc)
41 emsg.lpszSubject = argv[i];
42 } else if (strcmp(argv[i], "-m") == 0) { /* Message text */
43 if (++i < argc)
44 emsg.lpszNoteText = argv[i];
45 } else { /* address */
46 strncpy(addr, "SMTP:", sizeof(addr));
47 strncat(addr, argv[i], sizeof(addr));
48 recip.lpszAddress = addr;
49 recip.lpszName = argv[i];
53 err = MAPISendMail(0L, 0L, &emsg, 0L, 0L);
55 if (err != SUCCESS_SUCCESS) {
56 char buf[100];
57 snprintf(buf, sizeof(buf), "MAPI error code = %d", (int)err);
59 // Note, if we put up a dialogue box, this may stall the
60 // calling script, not a good thing.
61 // MessageBox(NULL, buf, "Error", MB_OK);
62 printf(buf);
63 exit(1);
65 exit(0);