Listing 2: GOPOSTAL.CPP Implementation file for your Internet server
gopostal extension
#include "stdafx.h"
#include "gopostal.h"
#include <afxsock.h>
#include <afx.h>
#include <stdlib.h>
#define BUFLEN 255
////////////////////////////////////////////////////////////////////
// The one and only CWinApp object
// NOTE: You may remove this object if you alter your project to no
// longer use MFC in a DLL.
CWinApp theApp;
////////////////////////////////////////////////////////////////////
// command-parsing map
BEGIN_PARSE_MAP(CGopostalExtension, CHttpServer)
// TODO: insert your ON_PARSE_COMMAND() and
// ON_PARSE_COMMAND_PARAMS() here to hook up your commands.
// For example:
ON_PARSE_COMMAND(Default, CGopostalExtension, ITS_EMPTY)
DEFAULT_PARSE_COMMAND(Default, CGopostalExtension)
ON_PARSE_COMMAND(Phillips, CGopostalExtension, ITS_PSTR ITS_PSTR ITS_PSTR
ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR
ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR
ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR
ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR ITS_PSTR
ITS_PSTR ITS_PSTR)
ON_PARSE_COMMAND_PARAMS("Date JBostic PHarrison JGreen
Jobnumber Firstname MI Lastname Address City State Zip Homephone
Workphone Extension School1 Degree1 GPA1 Cursalary Dessalary
Availdate Clearances Employed Lastworked Employer Division Industries
Whychange Position1 Position2 Skills Languages " )
END_PARSE_MAP(CGopostalExtension)
////////////////////////////////////////////////////////////////////
// The one and only CGopostalExtension object
CGopostalExtension theExtension;
////////////////////////////////////////////////////////////////////
// CGopostalExtension implementation
CGopostalExtension::CGopostalExtension()
{
}
CGopostalExtension::~CGopostalExtension()
{
}
BOOL CGopostalExtension::GetExtensionVersion(HSE_VERSION_INFO* pVer)
{
// Call default implementation for initialization
CHttpServer::GetExtensionVersion(pVer);
// Load description string
TCHAR sz[HSE_MAX_EXT_DLL_NAME_LEN+1];
ISAPIVERIFY(::LoadString(AfxGetResourceHandle(),
IDS_SERVER, sz, HSE_MAX_EXT_DLL_NAME_LEN));
_tcscpy(pVer->lpszExtensionDesc, sz);
return TRUE;
}
////////////////////////////////////////////////////////////////////
// CGopostalExtension command handlers
void CGopostalExtension::Default(CHttpServerContext* pCtxt)
{
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("This default message was produced by the Internet");
*pCtxt << _T(
" Server DLL Wizard. Edit your CGopostalExtension::Default()");
*pCtxt << _T(" implementation to change it.\r\n");
EndContent(pCtxt);
}
///////////////////////////////////////
// Handle the sbphillips on-line resume form
///////////////////////////////////////
void CGopostalExtension::Phillips(CHttpServerContext* pCtxt, LPTSTR
Date, LPTSTR JBostic, LPTSTR PHarrison, LPTSTR JGreen, LPTSTR
Jobnumber, LPTSTR Firstname, LPTSTR MI, LPTSTR Lastname, LPTSTR
Address, LPTSTR City, LPTSTR State, LPTSTR Zip, LPTSTR Homephone,
LPTSTR Workphone, LPTSTR Extension, LPTSTR School1, LPTSTR Degree1,
LPTSTR GPA1, LPTSTR Cursalary, LPTSTR Dessalary, LPTSTR Availdate,
LPTSTR Clearances, LPTSTR Employed, LPTSTR Lastworked, LPTSTR
Employer, LPTSTR Division, LPTSTR Industries, LPTSTR Whychange,
LPTSTR Position1, LPTSTR Position2, LPTSTR Skills, LPTSTR Languages )
{
// construct a CString object BUFLEN characters in length
CString buf( "x", BUFLEN );
// construct a socket
CSocket S;
S.Create();
// try to connect
if( ! S.Connect("email.acsinc.net", 25) ){
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("<h1>Can't open email</h1>");
EndContent(pCtxt);
return;
}
//construct a file object
CSocketFile f1( &S );
CSocketFile f2( &S );
//construct an archive
CArchive arOut( &f1, CArchive::store );
CArchive arIn( &f2, CArchive::load );
// Get the SMTP sign-on message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
//Check response - looking for 220 Service Ready
if( atoi( (LPCSTR)buf ) != 220 ) {
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("Error : ") << buf;
EndContent(pCtxt);
return;
}
// Say hello
arOut.WriteString("HELO WWW.ACSINC.NET\n");
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
//Check response - looking for 250 Requested Action Completed OK
if( atoi( (LPCSTR)buf ) != 250 ) {
arOut.WriteString("QUIT\n");
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("Error : ") << buf;
EndContent(pCtxt);
return;
}
// Send the MAIL FROM command
arOut.WriteString("MAIL FROM:<gateway@acsinc.net>\n" );
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
//Check response - looking for 250 Requested Action Completed OK
if( atoi( (LPCSTR)buf ) != 250 ) {
arOut.WriteString("QUIT\n");
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("Error : ") << buf;
EndContent(pCtxt);
return;
}
////// Send the RCPT TO command for each recipient /////
// Send to me for debugging
arOut.WriteString("RCPT TO: keith@acsinc.net\n");
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
if( *JBostic == 'Y'){
// Send to JBostic
arOut.WriteString("RCPT TO: jbostic@sbphillips.com\n");
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
}
if( *PHarrison == 'Y'){
// Send to PHarrison
arOut.WriteString("RCPT TO: pharrison@sbphillips.com\n");
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
}
if( *JGreen == 'Y'){
// Send to JGreen
arOut.WriteString("RCPT TO: jgreen@sbphillips.com\n");
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
}
// Send the DATA command
arOut.WriteString("DATA\n");
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
//Check response - looking for 354 Start Mail Input
if( atoi( (LPCSTR)buf ) != 354 ) {
arOut.WriteString("QUIT\n");
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("Error : ") << buf;
EndContent(pCtxt);
return;
}
arOut.WriteString(
"Subject: Email Gateway Copyright 1996 ACSinc.NET\n\n");
arOut.Flush();
//////////////// Send the body of the message here ///////////////
buf = "Date :"; buf += Date;
buf += "\nJBostic :"; buf += JBostic;
buf += "\nPHarrison :"; buf += PHarrison;
buf += "\nJGreen :"; buf += JGreen;
buf += "\nJob number(s) :"; buf += Jobnumber;
buf += "\nFirst name :"; buf += Firstname;
buf += " Middle initial :"; buf += MI;
buf += " Last name :"; buf += Lastname;
buf += "\nAddress :"; buf += Address;
buf += " City :"; buf += City;
buf += " State :"; buf += State;
buf += " Zipcode :"; buf += Zip;
buf += "\nHome phone :"; buf += Homephone;
buf += " Workphone :"; buf += Workphone;
buf += " Extension :"; buf += Extension;
buf += "\nSchool 1 :"; buf += School1;
buf += " Degree 1 :"; buf += Degree1;
buf += " GPA 1 :"; buf += GPA1;
buf += "\nCurrent salary :"; buf += Cursalary;
buf += " Desired salary :"; buf += Dessalary;
buf += "\nDate available :"; buf += Availdate;
buf += "\nSecurity clearances :";
buf += Clearances;
buf += "\nCurrently employed? :";
buf += Employed;
buf += " Date last worked :";buf += Lastworked;
buf += " Employer :"; buf += Employer;
buf += " Division :"; buf += Division;
buf += "\nIndustries worked in :";
buf += Industries;
buf += "\nWhy are you changeing jobs? :";
buf += Whychange;
buf += "\nPositions desired 1 :";
buf += Position1;
buf += "\n 2 :";
buf += Position2;
buf += "\nSkills :"; buf += Skills;
buf += "\nLanguages :"; buf += Languages;
///////// signal end of message /////////
buf += "\n.\n";
arOut.WriteString(buf);
arOut.Flush();
// Get SMTP response message
arIn.ReadString((char *)(LPCSTR)buf, BUFLEN);
//Check response - looking for 250 Requested Action Completed OK
if( atoi( (LPCSTR)buf ) != 250 ) {
arOut.WriteString("QUIT\n");
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("Error : ") << buf;
EndContent(pCtxt);
return;
}
// Quit SMTP session
arOut.WriteString("QUIT\n");
/////////// Send a response to the browser //////////
StartContent(pCtxt);
WriteTitle(pCtxt);
*pCtxt << _T("<h3>ACSinc.NET Form to Email Gateway</h3><hr>");
*pCtxt << _T(
"The following data has been emailed to these recipients:<br>");
*pCtxt << _T("<br>JBostic :") << JBostic;
*pCtxt << _T("<br>PHarrison :") << PHarrison;
*pCtxt << _T("<br>JGreen :") << JGreen;
*pCtxt << _T("<br>Job number(s) :") << Jobnumber;
*pCtxt << _T("<br>First name :") << Firstname;
*pCtxt << _T(" Middle initial :") << MI;
*pCtxt << _T(" Last name :") << Lastname;
*pCtxt << _T("<br>Address :") << Address;
*pCtxt << _T(" City :") << City;
*pCtxt << _T(" State :") << State;
*pCtxt << _T(" Zipcode :") << Zip;
*pCtxt << _T("<br>Home phone :") << Homephone;
*pCtxt << _T(" Workphone :") << Workphone;
*pCtxt << _T(" Extension :") << Extension;
*pCtxt << _T("<br>Current salary :") << Cursalary;
*pCtxt << _T(" Desired salary :") << Dessalary ;
*pCtxt << _T("<br>Date available :") << Availdate;
*pCtxt << _T("<br>Security clearances :") << Clearances;
*pCtxt << _T("<br>Currently employed? :") << Employed;
*pCtxt << _T(" Date last worked :") << Lastworked;
*pCtxt << _T(" Employer :") << Employer;
*pCtxt << _T(" Division :") << Division;
*pCtxt << _T("<br>Industries worked in :") << Industries;
*pCtxt << _T("<br>Why are you changeing jobs? :") << Whychange;
*pCtxt << _T("<br>Positions desired 1:") << Position1;
*pCtxt << _T(" 2 :") << Position2;
*pCtxt << _T("<br>Skills :") << Skills;
*pCtxt << _T("<br>Languages :") << Languages;
*pCtxt << _T("<br>School 1 :") << School1;
*pCtxt << _T(" Degree 1 :") << Degree1;
*pCtxt << _T(" GPA 1 :") << GPA1;
*pCtxt << _T(
"<hr>Thank you for taking the time to fill out the form.");
EndContent(pCtxt);
}
// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CGopostalExtension, CHttpServer)
//{{AFX_MSG_MAP(CGopostalExtension)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
///////////////////////////////////////////////////////////////////////
// If your extension will not use MFC, you'll need this code to make
// sure the extension objects can find the resource handle for the
// module. If you convert your extension to not be dependent on MFC,
// remove the comments arounn the following AfxGetResourceHandle()
// and DllMain() functions, as well as the g_hInstance global.
/****
static HINSTANCE g_hInstance;
HINSTANCE AFXISAPI AfxGetResourceHandle()
{
return g_hInstance;
}
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason,
LPVOID lpReserved)
{
if (ulReason == DLL_PROCESS_ATTACH)
{
g_hInstance = hInst;
}
return TRUE;
}
****/
//End of File