The program given in Example 7–3 demonstrates the following points:
Sending a message to multiple recipients.
Obtaining the status (legal, illegal) of each envelope recipient address (that is, active transport address).
The message is sent to one To: address, a Cc: address, and a Bcc: address. After mtaSend() is called, any status message associated with each address is displayed.
The log output produced by running the program is shown in Output for Example 3 Sending a Message to Multiple Recipients.
The following items of note are identified in the comments in the program:
Instruct mtaSend() to return a status message for each envelope recipient address.
Specify some To:, Cc:, and Bcc: addresses.
Send the message.
Display any returned status messages.
/* send_multi.c -- Send a message to multiple recipients */ #include <stdio.h\> #include <string.h\> #include "mtasdk.h" #define ITEM(item,adr) item_list[index].item_code = item;\ item_list[index].item_address = adr;\ item_list[index].item_length = adr ? strlen(adr) : 0;\ item_list[index].item_status = 0;\ item_list[index++].item_smessage = NULL main () { int index = 0, istat, i; mta_item_list_t item_list[7]; /* Specify the Subject: header line and message input source */ ITEM(MTA_SUBJECT, "send_multi.c"); ITEM(MTA_MSG_FILE, __FILE__); /* Return per address status/error messages */ ITEM(MTA_ADR_STATUS, 0); /* Instructs mtaSend() to return a */ /* status message for each envelope */ /* recipient address */ /* Specify regular Bcc:, To:, and Cc: addresses */ ITEM(MTA_BCC, "root"); ITEM(MTA_TO, "abuse@sample.com"); ITEM(MTA_CC, "postmaster@sample.com"); /* Now terminate the item list */ ITEM(MTA_END_LIST, 0); /* And send the message */ istat = mtaSend(item_list);/* Sends the message. */ /* Display the address status messages provided that no */ /* error other than MTA_HOST has occurred */ for (i = 0; i < index; i++) /* Display any returned status */ /* messages */ if (item_list[i].item_smessage) printf ("%s: %s - %s\n", (const char *)item_list[i].item_address, item_list[i].item_status ? "Failed" : "Succeeded", item_list[i].item_smessage); /* Dispose of status messages */ mtaSendDispose(item_list); exit(istat); } |
Succeeded: root@sample.com Succeeded: abuse@sample.com Succeeded: postmaster@sample.com |