home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 April / PCWorld_2000-04_cd.bin / Komunik / Servery / sambar / _setup.1 / sendmail.c < prev    next >
C/C++ Source or Header  |  1998-01-12  |  3KB  |  140 lines

  1. /*
  2. ** SENDMAIL
  3. **
  4. **      HTTP Wrapper for the Sendmail Utilities.
  5. **
  6. **        Confidential Property of Tod Sambar
  7. **        (c) Copyright Tod Sambar 1997
  8. **        All rights reserved.
  9. **
  10. **
  11. ** Public Functions:
  12. **
  13. **        sendmail_init
  14. **
  15. **
  16. ** History:
  17. ** Chg#    Date    Description                                                Resp
  18. ** ----    -------    -------------------------------------------------------    ----
  19. **         6APR97    Created                                                    sambar
  20. */
  21.  
  22. #include    <stdio.h>
  23. #include    <memory.h>
  24. #include    <string.h>
  25. #include    <stdlib.h>
  26. #include    <sendmail.h>
  27.  
  28. /*
  29. ** Sendmail parameters.
  30. */
  31. static SA_RPCPARAM        sendmailp [] =
  32. {
  33.     { "recipient",        1,    "Mail recipient." },
  34.     { "message",        1,    "Body of the mail." },
  35.     { "subject",        0,    "Mail subject." },
  36.     { "email",            1,    "Mail address of the sender." }
  37. };
  38.  
  39. /*
  40. **  SENDMAIL_INIT
  41. **
  42. **    Initialize the Sendmail RPC utilities.
  43. **
  44. **  Parameters:
  45. **    sactx        Sambar Server context
  46. **
  47. **  Returns:
  48. **    SA_SUCCEED | SA_FAIL
  49. */
  50. SA_RETCODE SA_PUBLIC
  51. sendmail_init(sactx)
  52. SA_CTX        *sactx;
  53. {
  54.     /* Register the Sendmail form RPC                                 */
  55.     if (sa_cmd_init(sactx, "sendmail", sendmailp, 
  56.         sizeof(sendmailp) / sizeof(SA_RPCPARAM), SA_AUTHORIZATION_ALL,
  57.         "Sendmail Form Utility", sendmail_form) != SA_SUCCEED)
  58.     {
  59.         sa_log(sactx, "Unable to initialize Sendmail Form RPC");
  60.         return (SA_FAIL);
  61.     } 
  62.  
  63.     sa_log(sactx, "Sendmail Utilities Initialized");
  64.  
  65.     return (SA_SUCCEED);
  66. }
  67.  
  68. /*
  69. **  SENDMAIL_FORM
  70. **
  71. **    Process a sendmail form and send the appropriate mail.
  72. **
  73. **  Parameters:
  74. **    sactx        Sambar Server context
  75. **    saconn        Sambar Server connection
  76. **    saparams    RPC Parameters
  77. **    infop        Error parameters
  78. **
  79. **  Returns:
  80. **    SA_SUCCEED | SA_FAIL
  81. */
  82. SA_RETCODE SA_PUBLIC
  83. sendmail_form(sactx, saconn, saparams, infop)
  84. SA_CTX        *sactx;
  85. SA_CONN        *saconn;
  86. SA_PARAMS    *saparams;
  87. SA_INT        *infop;
  88. {
  89.     SA_INT        emaillen;
  90.     SA_CHAR        *email;
  91.     SA_INT        tolen;
  92.     SA_CHAR        *to;
  93.     SA_INT        subjlen;
  94.     SA_CHAR        *subj;
  95.     SA_INT        msglen;
  96.     SA_CHAR        *msg;
  97.  
  98.     /* Get the mail recipient                                            */
  99.     if ((sa_param(sactx, saparams, "recipient", &to, &tolen) != SA_SUCCEED) ||
  100.         (tolen == 0))
  101.     {
  102.         *infop = SA_E_INVALIDDATA;
  103.         return (SA_FAIL);
  104.     }
  105.  
  106.     /* Get the mail message                                             */
  107.     if (sa_param(sactx, saparams, "message", &msg, &msglen) != SA_SUCCEED)
  108.     {
  109.         *infop = SA_E_INVALIDDATA;
  110.         return (SA_FAIL);
  111.     }
  112.  
  113.     /* If there is no message, just return                                */
  114.     if (msglen == 0)
  115.         return (SA_SUCCEED);
  116.  
  117.     /* Get the subject                                                     */
  118.     if (sa_param(sactx, saparams, "subject", &subj, &subjlen) != SA_SUCCEED)
  119.     {
  120.         *infop = SA_E_INVALIDDATA;
  121.         return (SA_FAIL);
  122.     }
  123.  
  124.     /* Get the "email"                                                     */
  125.     if ((sa_param(sactx, saparams, "email", &email, &emaillen) != SA_SUCCEED) ||
  126.         (emaillen == 0))
  127.     {
  128.         *infop = SA_E_INVALIDDATA;
  129.         return (SA_FAIL);
  130.     }
  131.  
  132.     if (sa_smtpmail(sactx, email, to, NULL, NULL, subj, msg, NULL) 
  133.         != SA_SUCCEED)
  134.     {
  135.         return (SA_FAIL);
  136.     }
  137.  
  138.     return (SA_SUCCEED);
  139. }
  140.