Libraries
texting_example/main.c
// ////////////////////////////////////////////////////////////////////////////
//
// Example program initializes the email library using an imaginary
// email account and attempts to send a text to an imaginary group of cell
// phone numbers. The configuration is saved in a file and the configuration
// file is then used to send a second text to an imaginary group of cell
// phone numbers. This program does not actually send a text. A real email
// account and group are required to actually send a text.
//
// ////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "trek_error.h"
#include <sys/timeb.h>
#include <string.h>
#include "ds_shared.h"
#ifdef __linux__
#include <unistd.h>
#else
#include <Windows.h>
#endif
// ////////////////////////////////////////////////////////////////////////////
//
// PrintTheMessage controls how messages are processed and displayed to
// the user.
//
// ////////////////////////////////////////////////////////////////////////////
void PrintTheMessage(message_struct_type *mess_struct_ptr)
{
printf("%s%s\n", GetMessageCategoryAsPaddedString(mess_struct_ptr->category),
mess_struct_ptr->message);
}
// ////////////////////////////////////////////////////////////////////////////
//
// Example program initializes the email library using an imaginary
// email account and attempts to send a text to an imaginary group of cell
// phone numbers. The configuration is saved in a file and the configuration
// file is then used to send a second text to an imaginary group of cell
// phone numbers. This program does not actually send a text. A real email
// account and group are required to actually send a text..
//
// ////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
char smtp_server_address[50];
char email_account_username[50];
char email_account_password[50];
char email_address[50];
char email_name[50];
boolean_type verify_cert_authorities;
boolean_type generate_curl_debug_messages;
char text_to_cell_phone_number[50];
char text_to_cell_phone_carrier[50];
char group_name[50];
char text[50];
strcpy(smtp_server_address, "smtp.gmail.com");
strcpy(email_account_username, "mrsock@gmail.com");
strcpy(email_account_password, "liveandprosper");
strcpy(email_address, "mrsock@gmail.com");
strcpy(email_name, "Mr Sock");
verify_cert_authorities = FALSE_OR_NO;
generate_curl_debug_messages = TRUE_OR_YES;
// Register the PrintMessage callback function prior to InitializeToolkitEmail to
// process error messages that may be generated during initialization
RegisterMessage(&PrintTheMessage);
// Intializes the email and texting library using input parameters. This function creates the
// texting thread.
if (InitializeToolkitEmail(smtp_server_address, email_account_username, email_account_password,
email_address, email_name, verify_cert_authorities, generate_curl_debug_messages) == SUCCESS)
{
// Adds "to" cell phone number to a list of cell phone numbers and associate the number with a
// group name.
strcpy(text_to_cell_phone_number, "123-456-7890");
strcpy(text_to_cell_phone_carrier, "T-MOBILE");
strcpy(group_name, "dogs rule");
if (AddTextToCellPhoneNumber(text_to_cell_phone_number, text_to_cell_phone_carrier, group_name) == SUCCESS)
{
strcpy(text_to_cell_phone_number, "2345678901");
strcpy(text_to_cell_phone_carrier, "AT&T");
// Add second cell phone number and associate the number with a group name.
if (AddTextToCellPhoneNumber(text_to_cell_phone_number, text_to_cell_phone_carrier, group_name) == SUCCESS)
{
// Create the text message.
strcpy(text, "Dogs are smarter than cats.");
// Sends the text to the designated cell phone numbers associated with the group name.
if (SendText(text, group_name) != SUCCESS)
{
printf("Error Failed to SendText.\n");
return 0;
}
}
else
{
printf("Error Failed to AddTextToCellPhoneNumber.\n");
return 0;
}
}
else
{
printf("Error Failed to AddTextToCellPhoneNumber.\n");
return 0;
}
}
else
{
printf("Error Failed to InitializeToolkitEmail.\n");
return 0;
}
// Sleep 10 second prior to exiting.
#ifdef __linux__
sleep(10);
#else
Sleep(10000);
#endif
char config_pathname[256];
char home_path[256];
if (TCAACGetHomeDirectory(home_path, sizeof(home_path)) != SUCCESS)
{
return(FAIL);
}
sprintf(config_pathname, "%s/email_config.txt", home_path);
// Save the configuration in a file
SaveToolkitEmailConfig(config_pathname);
// Now send a text using the configuration file
if (InitToolkitEmail(config_pathname, "liveandprosper") != SUCCESS)
{
printf("Error Failed to InitToolkitEmail.\n");
}
// Create the text message.
strcpy(text, "Dogs are smarter than cats.");
// Sends the text to the designated cell phone numbers associated with the group name.
if (SendText(text, group_name) != SUCCESS)
{
printf("Error Failed to SendEmail.\n");
return 0;
}
// Sleep 10 second prior to exiting.
#ifdef __linux__
sleep(10);
#else
Sleep(10000);
#endif
return 0;
}