home *** CD-ROM | disk | FTP | other *** search
- /*
- ** SENDMAIL
- **
- ** HTTP Wrapper for the Sendmail Utilities.
- **
- ** Confidential Property of Tod Sambar
- ** (c) Copyright Tod Sambar 1997
- ** All rights reserved.
- **
- **
- ** Public Functions:
- **
- ** sendmail_init
- **
- **
- ** History:
- ** Chg# Date Description Resp
- ** ---- ------- ------------------------------------------------------- ----
- ** 6APR97 Created sambar
- */
-
- #include <stdio.h>
- #include <memory.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sendmail.h>
-
- /*
- ** Sendmail parameters.
- */
- static SA_RPCPARAM sendmailp [] =
- {
- { "recipient", 1, "Mail recipient." },
- { "message", 1, "Body of the mail." },
- { "subject", 0, "Mail subject." },
- { "email", 1, "Mail address of the sender." }
- };
-
- /*
- ** SENDMAIL_INIT
- **
- ** Initialize the Sendmail RPC utilities.
- **
- ** Parameters:
- ** sactx Sambar Server context
- **
- ** Returns:
- ** SA_SUCCEED | SA_FAIL
- */
- SA_RETCODE SA_PUBLIC
- sendmail_init(sactx)
- SA_CTX *sactx;
- {
- /* Register the Sendmail form RPC */
- if (sa_cmd_init(sactx, "sendmail", sendmailp,
- sizeof(sendmailp) / sizeof(SA_RPCPARAM), SA_AUTHORIZATION_ALL,
- "Sendmail Form Utility", sendmail_form) != SA_SUCCEED)
- {
- sa_log(sactx, "Unable to initialize Sendmail Form RPC");
- return (SA_FAIL);
- }
-
- sa_log(sactx, "Sendmail Utilities Initialized");
-
- return (SA_SUCCEED);
- }
-
- /*
- ** SENDMAIL_FORM
- **
- ** Process a sendmail form and send the appropriate mail.
- **
- ** Parameters:
- ** sactx Sambar Server context
- ** saconn Sambar Server connection
- ** saparams RPC Parameters
- ** infop Error parameters
- **
- ** Returns:
- ** SA_SUCCEED | SA_FAIL
- */
- SA_RETCODE SA_PUBLIC
- sendmail_form(sactx, saconn, saparams, infop)
- SA_CTX *sactx;
- SA_CONN *saconn;
- SA_PARAMS *saparams;
- SA_INT *infop;
- {
- SA_INT emaillen;
- SA_CHAR *email;
- SA_INT tolen;
- SA_CHAR *to;
- SA_INT subjlen;
- SA_CHAR *subj;
- SA_INT msglen;
- SA_CHAR *msg;
-
- /* Get the mail recipient */
- if ((sa_param(sactx, saparams, "recipient", &to, &tolen) != SA_SUCCEED) ||
- (tolen == 0))
- {
- *infop = SA_E_INVALIDDATA;
- return (SA_FAIL);
- }
-
- /* Get the mail message */
- if (sa_param(sactx, saparams, "message", &msg, &msglen) != SA_SUCCEED)
- {
- *infop = SA_E_INVALIDDATA;
- return (SA_FAIL);
- }
-
- /* If there is no message, just return */
- if (msglen == 0)
- return (SA_SUCCEED);
-
- /* Get the subject */
- if (sa_param(sactx, saparams, "subject", &subj, &subjlen) != SA_SUCCEED)
- {
- *infop = SA_E_INVALIDDATA;
- return (SA_FAIL);
- }
-
- /* Get the "email" */
- if ((sa_param(sactx, saparams, "email", &email, &emaillen) != SA_SUCCEED) ||
- (emaillen == 0))
- {
- *infop = SA_E_INVALIDDATA;
- return (SA_FAIL);
- }
-
- if (sa_smtpmail(sactx, email, to, NULL, NULL, subj, msg, NULL)
- != SA_SUCCEED)
- {
- return (SA_FAIL);
- }
-
- return (SA_SUCCEED);
- }
-