We use 163, long pass Fei Hua and other free e-mail, we will find that these e-mail has the ability to send and receive online, that is, can be sent through the browser and receive e-mail messages. These features are typically implemented through CGI, and CGI technology is gradually being replaced by ISAPI/NSAPI technology, and the following example uses the ISAPI/NSAPI in c++builder4.0 to implement an online reception of e-mail. Using C++BUILDER4 to develop Web server programs is very simple, C++builder 4 VCL provides a large number of components and objects that support the development of Web server programs.
This program consists of two files, respectively, index.htm: The browser interface to receive e-mail, placed in the default directory of the Web server (such as: C:\Inetpub\wwwroot); ReadMail.dll: Display mailing lists in browsers and web for specifying message content Server application. This dynamic chain-node file is placed
Executable path (such as C:\Inetpub\scripts). User browses index.htm through Web server in the browser, enter host name, Port (general
is 110, user name, password, you will first see the user's mailing list, click the corresponding message number to view the content of the message.
First, the index.htm is established, and its contents are as follows:
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>邮件查看</title>
<body bgcolor="#FFFFFF">
<form action=" /scripts/MailList.dll/MailList"
method="POST">
<p>主机:<input type="text" size="20" name="Host"></p>
<p>端口:<input type="text" size="20" name="Port"></p>
<p>用户名:<input type="text" size="20" name="Name"></p>
<p>口令:<input type="password" size="20" name="Code"></p>
<p><input type="submit" name="B1" value="提交"><input
type="reset" name="B2" value="复原"></p>
</form>
</body>
Write ReadMail.dll below
Create a new ISAPI-based Web Server application in C++builder, manually increase
Nmpop31,pageproducer1. Define several variables in the Unit1.h header file:
Ansistring Hostname,hostport,username,usercode;
TStrings *urldata; Accept parameters passed by HTTP request
BOOL Connectflag;
int emailorder;
Add an action item with a path of/maillist, whose code is as follows:
void __fastcall twebmodule1::webmodule1webactionitem1action (
tobject *sender, Twebrequest *request, Twebresponse *response,
bool &handled)
{
//Accept the parameters passed by the HTTP request, from which the host, port, username, and password are obtained
urldata = NULL;
switch (request->methodtype)
{case Mtpost:
Urldata = request->contentfields;
break;
Case Mtget:
Urldata = request->queryfields;
break;
}
HostName = urldata->values["Host"];
Hostport = urldata->values["Port"];
UserName = urldata->values["Name"];
Usercode = urldata->values["Code"];
//below begins to connect to the mail server
nmpop31->attachfilepath= "."; /Store message path is current path
nmpop31->deleteonread=false;//does not delete replicas on the server
nmpop31->reportlevel=status_basic;//status level of detail
nmpop31->timeout=20000;//Set Timeout
nmpop31->host=hostname;
Nmpop31->port=strtoint (Hostport);
nmpop31->userid=username;
nmpop31->password=usercode;
connectflag=true;
Nmpop31->connect ();
//If the connection succeeds, make the HTML statement for the mailing list
if (connectflag)
{pageproducer1->htmldoc->clear ();
Pageproducer1->htmldoc->add ("<html><body>");
Pageproducer1->htmldoc->add ("Number of messages" +inttostr (Nmpop31->mailcount));
if (nmpop31->mailcount)
for (int i=1;i<=nmpop31->mailcount;i++)
{Pageproducer1->htmldoc->add ("<a href=");
pageproducer1->htmldoc->add ("Readmail? Mx= ");
Pageproducer1->htmldoc->add (IntToStr (i));
pageproducer1->htmldoc->add ("' >");
Pageproducer1->htmldoc->add (IntToStr (i));
Pageproducer1->htmldoc->add ("</a>");}
}
Pageproducer1->htmldoc->add ("</body></html>");
nmpop31->disconnect ();}
Else
{pageproducer1->htmldoc->clear ();
Pageproducer1->htmldoc->add ("<html><body>");
pageproducer1->htmldoc->add ("Connection server failed!") ");
Pageproducer1->htmldoc->add ("</body></html>");}
//Send HTML statement of mailing list to browser
response->content = Pageproducer1->content ();
}
//--------------------------------------------------------------