cgi_mail.c File Reference

#include "cgi.h"
#include <winsock2.h>
#include "xcmc.h"
#include "xcmcext.h"
#include "xcmcmsxt.h"

Include dependency graph for cgi_mail.c:

Go to the source code of this file.

Defines

#define CMC_USE_MSWIN_NT
#define CMC_API   FAR PASCAL
#define CMC_CALLBACK   CMC_API *

Typedefs

typedef CMC_ui_id ui_id
typedef CMC_ui_id CMC_flags logoff_flags
typedef CMC_ui_id CMC_flags
CMC_extension
logoff_extensions
typedef CMC_recipientrecipient_in
typedef CMC_recipient CMC_flags look_up_flags
typedef CMC_recipient CMC_flags
CMC_ui_id CMC_uint32
count
typedef CMC_recipient CMC_flags
CMC_ui_id CMC_uint32 CMC_recipient ** 
recipient_out
typedef CMC_recipient CMC_flags
CMC_ui_id CMC_uint32 CMC_recipient
CMC_extension
look_up_extensions
typedef CMC_string user
typedef CMC_string CMC_string password
typedef CMC_string CMC_string
CMC_object_identifier 
character_set
typedef CMC_string CMC_string
CMC_object_identifier CMC_ui_id
CMC_uint16 
caller_cmc_version
typedef CMC_string CMC_string
CMC_object_identifier CMC_ui_id
CMC_uint16 CMC_flags 
logon_flags
typedef CMC_string CMC_string
CMC_object_identifier CMC_ui_id
CMC_uint16 CMC_flags CMC_session_id
session
typedef CMC_string CMC_string
CMC_object_identifier CMC_ui_id
CMC_uint16 CMC_flags CMC_session_id
CMC_extension
logon_extensions
typedef CMC_messagemessage
typedef CMC_message CMC_flags send_flags
typedef CMC_message CMC_flags
CMC_ui_id CMC_extension
send_extensions

Functions

int WinsockConnect (char *host, int port, unsigned int *s)
int Reply (unsigned int s)
int SMTPSendMail (char *host, char *subject, char *recip, char *textnote)
typedef CMC_return_code (FAR PASCAL *PCMCLOGOFF)(CMC_session_id session
int CMCSendMail (char *recip, char *subject, char *textnote, char *profile, char *name, char *password)
int SendMail (char *recip, char *subject, char *text, char *server, char *profile, char *name, char *password)


Define Documentation

#define CMC_API   FAR PASCAL
 

Definition at line 160 of file cgi_mail.c.

#define CMC_CALLBACK   CMC_API *
 

Definition at line 161 of file cgi_mail.c.

#define CMC_USE_MSWIN_NT
 

Definition at line 148 of file cgi_mail.c.


Typedef Documentation

typedef CMC_string CMC_string CMC_object_identifier CMC_ui_id CMC_uint16 caller_cmc_version
 

Definition at line 180 of file cgi_mail.c.

typedef CMC_string CMC_string CMC_object_identifier character_set
 

Definition at line 180 of file cgi_mail.c.

typedef CMC_recipient CMC_flags CMC_ui_id CMC_uint32* count
 

Definition at line 171 of file cgi_mail.c.

typedef CMC_ui_id CMC_flags CMC_extension* logoff_extensions
 

Definition at line 165 of file cgi_mail.c.

typedef CMC_ui_id CMC_flags logoff_flags
 

Definition at line 165 of file cgi_mail.c.

typedef CMC_string CMC_string CMC_object_identifier CMC_ui_id CMC_uint16 CMC_flags CMC_session_id CMC_extension* logon_extensions
 

Definition at line 180 of file cgi_mail.c.

typedef CMC_string CMC_string CMC_object_identifier CMC_ui_id CMC_uint16 CMC_flags logon_flags
 

Definition at line 180 of file cgi_mail.c.

typedef CMC_recipient CMC_flags CMC_ui_id CMC_uint32 CMC_recipient CMC_extension* look_up_extensions
 

Definition at line 171 of file cgi_mail.c.

typedef CMC_recipient CMC_flags look_up_flags
 

Definition at line 171 of file cgi_mail.c.

typedef CMC_message* message
 

Definition at line 191 of file cgi_mail.c.

typedef CMC_string CMC_string password
 

Definition at line 180 of file cgi_mail.c.

typedef CMC_recipient* recipient_in
 

Definition at line 171 of file cgi_mail.c.

typedef CMC_recipient CMC_flags CMC_ui_id CMC_uint32 CMC_recipient** recipient_out
 

Definition at line 171 of file cgi_mail.c.

typedef CMC_message CMC_flags CMC_ui_id CMC_extension* send_extensions
 

Definition at line 191 of file cgi_mail.c.

typedef CMC_message CMC_flags send_flags
 

Definition at line 191 of file cgi_mail.c.

typedef CMC_string CMC_string CMC_object_identifier CMC_ui_id CMC_uint16 CMC_flags CMC_session_id* session
 

Definition at line 180 of file cgi_mail.c.

typedef CMC_message CMC_flags CMC_ui_id ui_id
 

Definition at line 165 of file cgi_mail.c.

typedef CMC_string user
 

Definition at line 180 of file cgi_mail.c.


Function Documentation

typedef CMC_return_code FAR PASCAL *  PCMCLOGOFF  ) 
 

int CMCSendMail char *  recip,
char *  subject,
char *  textnote,
char *  profile,
char *  name,
char *  password
 

Definition at line 199 of file cgi_mail.c.

References CMC_recipient::address, CMC_message::attachments, CMC_LOOKUP_RESOLVE_PREFIX_SEARCH, CMC_MSG_UNSENT, CMC_RECIP_LAST_ELEMENT, CMC_ROLE_TO, CMC_TYPE_UNKNOWN, CMC_VERSION, CMC_message::message_extensions, CMC_message::message_flags, CMC_message::message_reference, CMC_message::message_type, CMC_recipient::name, CMC_recipient::name_type, NULL, CMC_recipient::recip_extensions, CMC_recipient::recip_flags, CMC_message::recipients, CMC_recipient::role, CMC_message::subject, CMC_message::text_note, and CMC_message::time_sent.

Referenced by SendMail().

00201 {
00202   PCMCLOGOFF              CMCLogoff;
00203   PCMCLOGON               CMCLogon;
00204   PCMCSEND                CMCSend;
00205   PCMCLOOKUP              CMCLookUp;
00206   PCMCFREE                CMCFree;
00207   CMC_session_id   cmcSessionID;
00208   char LibName[1024];
00209   HANDLE library;
00210   CMC_return_code cmcsts;
00211   CMC_recipient recipient;
00212   CMC_recipient * CMCReciparray=0;
00213   CMC_message  message;
00214   unsigned long int recipcount = 1;
00215 
00216   /* load library */
00217 
00218   GetProfileString("Mail", "CMCDLLNAME32", "MAPI32.DLL", LibName, 1024);
00219   library = LoadLibrary(LibName);
00220   if ((UINT) library < 32) return 31;
00221 
00222   /* log on */
00223   CMCLogoff = (PCMCLOGOFF)GetProcAddress(library,"cmc_logoff");
00224   CMCLogon  = (PCMCLOGON) GetProcAddress(library,"cmc_logon");
00225   CMCSend   = (PCMCSEND)  GetProcAddress(library,"cmc_send");
00226   CMCLookUp = (PCMCLOOKUP)GetProcAddress(library,"cmc_look_up");
00227   CMCFree   = (PCMCFREE)GetProcAddress(library,"cmc_free");
00228 
00229   if (!CMCLogoff || !CMCLogon || !CMCSend || !CMCFree)
00230   {FreeLibrary(library); return 32;}
00231 
00232   cmcsts = CMCLogon(profile,name,password,0,0,
00233                     CMC_VERSION,0,&cmcSessionID,0);
00234 
00235   if (cmcsts) {FreeLibrary(library); return 32;}
00236 
00237   /* look up address */
00238   recipient.name = recip;
00239   recipient.name_type = CMC_TYPE_UNKNOWN;
00240   recipient.address = NULL;
00241   recipient.role = CMC_ROLE_TO;
00242   recipient.recip_flags = 0;
00243   recipient.recip_extensions = NULL;
00244   recipient.recip_flags = CMC_RECIP_LAST_ELEMENT;
00245 
00246   if (CMCLookUp)
00247    cmcsts = CMCLookUp(cmcSessionID,
00248                      &recipient,
00249                      CMC_LOOKUP_RESOLVE_PREFIX_SEARCH,
00250                      0,
00251                      &recipcount,
00252                      &CMCReciparray,
00253                      0
00254                      );
00255 
00256   if (cmcsts)
00257    {
00258     CMCLogoff(cmcSessionID,0,0,0);
00259     FreeLibrary(library);
00260     return 33;
00261    }
00262 
00263   /* send message */
00264 
00265    message.message_reference  =NULL;
00266    message.message_type       = "CMC: IPM";
00267    message.subject            = subject;
00268    memset(&message.time_sent,0,sizeof(message.time_sent));
00269    message.text_note          = textnote;
00270    message.recipients         = CMCReciparray;
00271    message.attachments        = NULL;
00272    message.message_flags      = CMC_MSG_UNSENT;
00273    message.message_extensions = NULL;
00274 
00275   cmcsts = CMCSend(cmcSessionID,&message,0,0,0);
00276 
00277   if (cmcsts)
00278    {
00279     CMCFree(CMCReciparray);
00280     CMCLogoff(cmcSessionID,0,0,0);
00281     FreeLibrary(library);
00282     return 34;
00283    }
00284 
00285   /* log off */
00286 
00287   CMCFree(CMCReciparray);
00288   CMCLogoff(cmcSessionID,0,0,0);
00289   FreeLibrary(library);
00290   /* done */
00291   return 0;
00292 }

int Reply unsigned int  s  ) 
 

Definition at line 26 of file cgi_mail.c.

Referenced by SMTPSendMail().

00027 {
00028   char reply[256];
00029   int i=0;
00030   for (i=0; i<256; i++)
00031   {
00032       if (!recv(s, reply+i, 1, 0))
00033           return 0;
00034       if (reply[i] == '\n')
00035        {
00036          reply[i]=0;
00037          break;
00038        }
00039   }
00040 
00041   reply[255]=0;
00042   return atoi(reply);
00043 }

int SendMail char *  recip,
char *  subject,
char *  textnote,
char *  server,
char *  profile,
char *  name,
char *  password
 

Use sendmail -t on UNIX, Exchange on Windows on UNIX, the last 4 parameters are ignored.

Definition at line 295 of file cgi_mail.c.

References CMCSendMail(), and SMTPSendMail().

Referenced by CGImain(), JSSendMail(), and SaveData().

00297 {
00298  int i = 1;
00299 
00300      if (server)
00301       if (*server)
00302        i = SMTPSendMail(server, subject, recip, text);
00303 
00304      if (i != 0)
00305       i = CMCSendMail(recip, subject,text,profile,name,password);
00306 
00307  return i;
00308 }

int SMTPSendMail char *  host,
char *  subject,
char *  recip,
char *  textnote
 

Definition at line 45 of file cgi_mail.c.

References Reply(), strnicmp(), and WinsockConnect().

Referenced by SendMail().

00046 {
00047  unsigned int s;
00048 #if defined(XP_WIN)
00049  WSADATA d;
00050 #else
00051 #define INVALID_SOCKET 0xffffffff
00052 #endif
00053  int err;
00054 
00055 #if defined(XP_WIN)
00056  if (WSAStartup(2, &d) != 0)     /* init winsock lib. want v2.0 */
00057   {
00058    WSACleanup();
00059    return 61;
00060   }
00061 #endif
00062 
00063  err = WinsockConnect(host, 25, &s);
00064  if (!err)
00065  {
00066   err = 2;
00067 
00068   if (Reply(s) != 220) goto done;
00069   send(s, "HELO ", 5, 0);
00070   send(s, host, strlen(host), 0);
00071   send(s, "\r\n", 2, 0);
00072 
00073   if (Reply(s) != 250) goto done;
00074 
00075   err = 0;
00076   send(s, "MAIL FROM: <", 14, 0);
00077   send(s, recip, strlen(recip), 0);
00078   send(s, ">\r\nRCPT TO: <", 13, 0);
00079   send(s, recip, strlen(recip), 0);
00080   send(s, ">\r\nDATA\r\n", 9, 0);
00081   send(s, "Subject: ", 9, 0);
00082   send(s, subject, strlen(subject), 0);
00083   send(s, "\r\nFrom: ", 8, 0);
00084   send(s, recip, strlen(recip), 0);
00085   send(s, "\r\nTo: ", 7, 0);
00086   send(s, recip, strlen(recip), 0);
00087 
00088   if (strnicmp(textnote,"<HTML",5))
00089   {
00090    send(s, "\r\n\r\n", 4,0);
00091    send(s, textnote,strlen(textnote),0);
00092   }
00093   else
00094   {
00095    char*c = "\r\nMIME-Version: 1.0\r\n"
00096             "Content-Type: multipart/alternative; boundary=\"_Mime-Boundary_72616F\"\r\n\r\n";
00097    send(s,c , strlen(c),0);
00098    c = "  This is a multi-part message in MIME format.\r\n\r\n"
00099        "--_Mime-Boundary_72616F\r\n"
00100        "Content-Type: text/html; charset=\"utf-8\""
00101        "Content-Transfer-Encoding: 8bit\r\n\r\n";
00102    send(s,c , strlen(c),0);
00103    send(s, textnote,strlen(textnote),0);
00104    c = "\r\n--_Mime-Boundary_72616F--";
00105    send(s,c , strlen(c),0);
00106   }
00107 
00108  send(s, "\r\n.\r\n" , 5 , 0);
00109 
00110  }
00111 
00112 done:
00113  if (s != INVALID_SOCKET) /* shutdown and close the socket if needed */
00114    {
00115      send(s, "QUIT\r\n" , 6 , 0);
00116      shutdown(s, 2);   /* shutdown both channels (read+write) */
00117 #ifdef XP_WIN
00118     closesocket(s);
00119 #endif
00120 #ifdef XP_UNIX
00121     close(s);
00122 #endif
00123    }
00124 
00125 #if defined(XP_WIN)
00126  WSACleanup();
00127 #endif
00128 
00129  return err;
00130 }

int WinsockConnect char *  host,
int  port,
unsigned int *  s
 

defined in cgi_soap.c

Definition at line 31 of file cgi_soap.c.

00032 {
00033  long int hostaddr = 0;
00034  unsigned long *p;
00035  struct sockaddr_in svraddr;
00036  struct hostent *he;
00037  *s = INVALID_SOCKET;
00038 
00039  if (isdigit(host[0]))        /* something like 192.168.0.1 */
00040    {
00041       hostaddr = inet_addr(host);      /* convert to 32bit unsigned int */
00042    }
00043  else                         /* something like phoenix.ttdev.com */
00044    {
00045       he = gethostbyname(host); /* convert to 32bit unsigned int */
00046       if (!he) {return 62;}
00047       p = (unsigned long*)he->h_addr_list[0];
00048       hostaddr = *p;
00049    }
00050 
00051    *s = socket(AF_INET, SOCK_STREAM, 0); /* make Internet socket */
00052 
00053    if (*s == INVALID_SOCKET) return 63;
00054 
00055    svraddr.sin_family = AF_INET;       /* Internet address family */
00056    svraddr.sin_port = htons(port);     /* port */
00057    memcpy(&svraddr.sin_addr.s_addr, &hostaddr, sizeof(INADDR_ANY)); /* host addr */
00058    memset(svraddr.sin_zero,0,sizeof(svraddr.sin_zero));
00059 
00060    if (connect(*s, (SOCKADDR*)&svraddr, sizeof(svraddr)) != 0)
00061     return 64;
00062 
00063    return 0;
00064 }



Raosoft, Inc.
Raosoft EZReport, EZSurvey, InterForm, RapidReport, Raosoft, and SurveyWin are registered trademarks of Raosoft, Inc. Page contents © 1996-2007 by Raosoft, Inc. You may use and modify this file for your own use, but may not distribute it or derivative works without the prior written consent of Raosoft, Inc. This software is provided "as is," and Raosoft makes no warranty, express or implied, of fitness for a particular application. Every measure has been taken to anticipate risks inherent to computer networks, but we cannot guarantee safety or reliability of this program in every situation.
Tel: 206-525-4025 (US) Email: raosoft@raosoft.com
http://www.raosoft.com/