C + + Builder realize online receive email

Source: Internet
Author: User
Tags bool http request microsoft frontpage

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 &amp;handled)


{


//Accept the parameters passed by the HTTP request, from which the host, port, username, and password are obtained


urldata = NULL;


switch (request-&gt;methodtype)


{case Mtpost:


Urldata = request-&gt;contentfields;


break;


Case Mtget:


Urldata = request-&gt;queryfields;


break;


}


HostName = urldata-&gt;values["Host"];


Hostport = urldata-&gt;values["Port"];


UserName = urldata-&gt;values["Name"];


Usercode = urldata-&gt;values["Code"];


//below begins to connect to the mail server


nmpop31-&gt;attachfilepath= "."; /Store message path is current path


nmpop31-&gt;deleteonread=false;//does not delete replicas on the server


nmpop31-&gt;reportlevel=status_basic;//status level of detail


nmpop31-&gt;timeout=20000;//Set Timeout


nmpop31-&gt;host=hostname;


Nmpop31-&gt;port=strtoint (Hostport);


nmpop31-&gt;userid=username;


nmpop31-&gt;password=usercode;


connectflag=true;


Nmpop31-&gt;connect ();


//If the connection succeeds, make the HTML statement for the mailing list


if (connectflag)


{pageproducer1-&gt;htmldoc-&gt;clear ();


Pageproducer1-&gt;htmldoc-&gt;add ("&lt;html&gt;&lt;body&gt;");


Pageproducer1-&gt;htmldoc-&gt;add ("Number of messages" +inttostr (Nmpop31-&gt;mailcount));


if (nmpop31-&gt;mailcount)


for (int i=1;i&lt;=nmpop31-&gt;mailcount;i++)


{Pageproducer1-&gt;htmldoc-&gt;add ("&lt;a href=");


pageproducer1-&gt;htmldoc-&gt;add ("Readmail? Mx= ");


Pageproducer1-&gt;htmldoc-&gt;add (IntToStr (i));


pageproducer1-&gt;htmldoc-&gt;add ("' &gt;");


Pageproducer1-&gt;htmldoc-&gt;add (IntToStr (i));


Pageproducer1-&gt;htmldoc-&gt;add ("&lt;/a&gt;");}


}


Pageproducer1-&gt;htmldoc-&gt;add ("&lt;/body&gt;&lt;/html&gt;");


nmpop31-&gt;disconnect ();}


Else


{pageproducer1-&gt;htmldoc-&gt;clear ();


Pageproducer1-&gt;htmldoc-&gt;add ("&lt;html&gt;&lt;body&gt;");


pageproducer1-&gt;htmldoc-&gt;add ("Connection server failed!") ");


Pageproducer1-&gt;htmldoc-&gt;add ("&lt;/body&gt;&lt;/html&gt;");}


//Send HTML statement of mailing list to browser


response-&gt;content = Pageproducer1-&gt;content ();


}


//--------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.