Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:scripts:sms-to-email [2015/05/05 17:04] (current)
Line 1: Line 1:
 +====== SDK Script sms-to-email.are ======
 +<code c sms-to-email.are>​
 +/* DESC: This script will forward incoming SMS messages to a given E-mail address.
 + * Copyright (C) 2012 NetModule AG, Switzerland
 + */
 +
 +if (argc < 1 || strlen(argv[1]) == 0) {
 +    printf("​usage:​ sms-to-email.are <​email-rcpt>"​);​
 +    exit(1);
 +}
 +
 +rcpt = argv[1];
 +
 +while(1) {
 +    msgs = nb_sms_list();​
 +    nr_msgs = length(msgs);​
 +
 +    if (nr_msgs == 0) {
 +        sleep(10);
 +        continue;
 +    }
 +
 +    for (i=0; i<​nr_msgs;​ i++) {
 +        msg = nb_sms_retrieve(msgs[i]);​
 +        if (!msg) continue;
 +
 +        nb_syslog("​processing message %d of %d (ID %s)",
 +                   i, nr_msgs, msgs[i]);
 +
 +        subject = "SMS received";​
 +        sprintf(body,​ "​%s\n",​ msg);
 +
 +        if (nb_email_send(rcpt,​ subject, body) != 0) {
 +            printf("​unable to send e-mail\n"​);​
 +        } else {
 +            printf("​successfully sent e-mail\n"​);​
 +        }
 +    }
 +}
 +
 +exit(0);
 +
 +</​code>​