home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 January
/
PCWorld_2001-01_cd.bin
/
Software
/
Topware
/
sambar
/
_SETUP.1
/
sendmail.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-05
|
4KB
|
191 lines
/*
** 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", 1, "Mail subject." },
{ "email", 1, "Mail address of the sender." },
{ "attachment", 0, "File to send as an attachment." }
};
/*
** 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
** Note: This can only be called from RCXsendmail, register
** sendmail_init2 to allow sendmail to be called via
** /session/sendmail
*/
if (sa_cmd_init(sactx, "sendmail", sendmailp,
sizeof(sendmailp) / sizeof(SA_RPCPARAM), SA_AUTHORIZATION_SCRIPT,
"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_INITALL2
**
** Initialize the Sendmail RPC utilities (open to all use).
**
** WARNING! Initialzing this interface allows you sendmail
** script to be used as a SPAM relay point.
**
** Parameters:
** sactx Sambar Server context
**
** Returns:
** SA_SUCCEED | SA_FAIL
*/
SA_RETCODE SA_PUBLIC
sendmail_init2(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;
SA_INT attachlen;
SA_CHAR *attach;
/* Get the mail recipient */
if ((sa_param(sactx, saparams, "recipient", &to, &tolen) != SA_SUCCEED)
|| (tolen == 0) || (tolen > 255))
{
*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 (optional) */
if ((sa_param(sactx, saparams, "subject", &subj, &subjlen) != SA_SUCCEED)
|| (subjlen > 255))
{
*infop = SA_E_INVALIDDATA;
return (SA_FAIL);
}
/* Get the "email" */
if ((sa_param(sactx, saparams, "email", &email, &emaillen) != SA_SUCCEED)
|| (emaillen == 0) || (emaillen > 255))
{
*infop = SA_E_INVALIDDATA;
return (SA_FAIL);
}
/* Get the attachment (optional) */
if (sa_param(sactx, saparams, "attachment", &attach, &attachlen)
!= SA_SUCCEED)
{
attach = (SA_CHAR *)NULL;
}
if (attachlen == 0)
attach = (SA_CHAR *)NULL;
if (sa_smtpmail(sactx, email, to, NULL, NULL, subj, msg, attach)
!= SA_SUCCEED)
{
return (SA_FAIL);
}
return (SA_SUCCEED);
}