home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / WEBSERVE / SAMBAR / DATA.1 / sendmail.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  3KB  |  128 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_INIT
  30. **
  31. **    Initialize the Sendmail RPC utilities.
  32. **
  33. **  Parameters:
  34. **    sactx        Sambar Server context
  35. **
  36. **  Returns:
  37. **    SA_SUCCEED | SA_FAIL
  38. */
  39. SA_RETCODE SA_PUBLIC
  40. sendmail_init(sactx)
  41. SA_CTX        *sactx;
  42. {
  43.     /* Register the Sendmail form RPC                                 */
  44.     if (sa_cmd_init(sactx, "sendmail", SA_AUTHORIZATION_ALL,
  45.         "Sendmail Form Utility", sendmail_form) != SA_SUCCEED)
  46.     {
  47.         sa_log(sactx, "Unable to initialize Sendmail Form RPC");
  48.         return (SA_FAIL);
  49.     } 
  50.  
  51.     sa_log(sactx, "Sendmail Utilities Initialized");
  52.  
  53.     return (SA_SUCCEED);
  54. }
  55.  
  56. /*
  57. **  SENDMAIL_FORM
  58. **
  59. **    Process a sendmail form and send the appropriate mail.
  60. **
  61. **  Parameters:
  62. **    sactx        Sambar Server context
  63. **    saconn        Sambar Server connection
  64. **    saparams    RPC Parameters
  65. **    infop        Error parameters
  66. **
  67. **  Returns:
  68. **    SA_SUCCEED | SA_FAIL
  69. */
  70. SA_RETCODE SA_PUBLIC
  71. sendmail_form(sactx, saconn, saparams, infop)
  72. SA_CTX        *sactx;
  73. SA_CONN        *saconn;
  74. SA_PARAMS    *saparams;
  75. SA_INT        *infop;
  76. {
  77.     SA_INT        emaillen;
  78.     SA_CHAR        *email;
  79.     SA_INT        tolen;
  80.     SA_CHAR        *to;
  81.     SA_INT        subjlen;
  82.     SA_CHAR        *subj;
  83.     SA_INT        msglen;
  84.     SA_CHAR        *msg;
  85.  
  86.     /* Get the mail recipient                                            */
  87.     if ((sa_param(sactx, saparams, "recipient", &to, &tolen) != SA_SUCCEED) ||
  88.         (tolen == 0))
  89.     {
  90.         *infop = SA_E_INVALIDDATA;
  91.         return (SA_FAIL);
  92.     }
  93.  
  94.     /* Get the mail message                                             */
  95.     if (sa_param(sactx, saparams, "message", &msg, &msglen) != SA_SUCCEED)
  96.     {
  97.         *infop = SA_E_INVALIDDATA;
  98.         return (SA_FAIL);
  99.     }
  100.  
  101.     /* If there is no message, just return                                */
  102.     if (msglen == 0)
  103.         return (SA_SUCCEED);
  104.  
  105.     /* Get the subject                                                     */
  106.     if (sa_param(sactx, saparams, "subject", &subj, &subjlen) != SA_SUCCEED)
  107.     {
  108.         *infop = SA_E_INVALIDDATA;
  109.         return (SA_FAIL);
  110.     }
  111.  
  112.     /* Get the "email"                                                     */
  113.     if ((sa_param(sactx, saparams, "email", &email, &emaillen) != SA_SUCCEED) ||
  114.         (emaillen == 0))
  115.     {
  116.         *infop = SA_E_INVALIDDATA;
  117.         return (SA_FAIL);
  118.     }
  119.  
  120.     if (sa_smtpmail(sactx, email, to, NULL, NULL, subj, msg, NULL) 
  121.         != SA_SUCCEED)
  122.     {
  123.         return (SA_FAIL);
  124.     }
  125.  
  126.     return (SA_SUCCEED);
  127. }
  128.