Delphi Development Webmail Program

zhaozj2021-02-17  70

Delphi4 Development Webmail Program

Often, implementation of Webmail's CGI with MailTo.exe, writes "

"statement or calls the Windows API function in the HTML file. The Windows API is written in the HTML file "" statement requires the user's browser to load Exchange, OutlookExpress, or Outlook and other software, and some browsing The Mailto statement does not support. The use of CGI is implemented in the form of Webmail does not require the user's browser, but the efficiency is not high. CGI technology is gradually being replaced by ISAPI / NSAPI technology. This article discusses the use of ISAPI technology to implement Webmail. Developing a Web Server program using Delphi 4 is very simple, and a large number of components and objects are provided in Delphi 4, supporting the development of the web server program. By following an example, you will use Delphi to develop a webmail program that is an ISAPI entered by the user. Only users registered on the send server can send emails in the browser. For the sake of simplicity, the program does not provide confidentiality for the transmitted data. First, install the database engine DBE at the web server side, and set the database alias: YH, point to a database file User.db containing the username and user password. Then establish two HTML files, names: DL.html, Qd.html, place in the default directory of the web server (such as: c: / inetpub / wwwroot). The content of DL.html is as follows: Send Mail System </ Title> </ head> <body> <h1> Send Mail System </ H1> <P> Please enter your username and password.</p> <p></ p> <form method = "post" action = "/ scripts / xsmd"> <p> Username: <input type = "text" length = 10 name = "username"> password: <input type = "Password "Length = 10 name =" password "> </ p> <p> <input type =" submit "value =" OK "> <input type =" reset "value =" Clear "> </ p> </ form > </ body> </ html> QD.html file content is as follows: <html> <head> <title> Fill in the </ Title> </ head> <body> <form method = "post" action = "feedback" > <P> Please fill in the received email address: toaddress: <input type = "text" length = 20 name = "toaddress"> </ p> <p> Please fill in the topic. <input type = "text" length = 20 name = "subject"> </ p> <p> content: </ p> <p> <input type = "textarea" length = 40 width = 40 Name = "body" > </ p> <p> <input type = "submit" value = "OK"> <input type = "reset" value = "Clear"> </ p> </ form> </ body> </ html> In Delphi, create a new ISAPI-based web server application, manually increase NMSMTP1, Query1, and pageproducer1. Where: htmlfile: c: /inetpub/www.root/qd.html is: htmlfile: c: /inetpub/www.root/qd.html. NMSMTP1 Property: Host (Send the address of the mail server.) here is SMTP.NETEASE.COM.. Port: 25.</p> <p>Global variables: sername: string; flag: boolean; increase of a path / feedback action items, which code is as follows: procedure TWebModule1.WebModule1WebActionItem1 Action (Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); VAR Count: Integer; s: string; begin query1.close; query1.sql.clear; s: = 'select count (username) from user.db where username = "; s: = s request.contentfields.values ​​[ 'Username'] '"; s: = s ' and password ="; s: = s request.contentfields.values ​​['psword'] '"; query1.sql.add (s); query1 .open; if query1.count = 0 Then response.content: = '<html> <head> <title> </ title> <body> username, password is incorrect, please re-enter </ body> </ html> 'Else username: = request.contentfields.values ​​[' username ']; response.content: = pageproducer1.content; End; add a path / sendmail action items, which program code is as follows: procedure TWebModule1.WebModule1Web ActionItem2Action ( Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); var body: string; Begin Flag: = true; body: = request.contentfields.values ​​[ 'body']; Pageproducer1.htmldoc.clear; Pagepr oducer1.htmldoc.add ( '<html> <body>'); Nmsmtp1.postmessage.clear; Nmsmtp1.postmessage.fromaddress: = username '@ netease.com'; Nmsmtp1.postmessage.from: = username; Nmsmtp1.postmessage. body.add (body); Nmsmtp1.postmessage.toaddress.add (request.contentfields.values ​​[ 'toaddress']); Nmsmtp1.postmessage.subject: = request.contentfields.values ​​[ 'subject']; Nmsmtp1.connect; If Flag = True Then Begin nmsmtp1.sendmail; nmsmtp1.disconntent; end pageProducer1.htmldoc.add ('</ body> </ html>); response.content; end;</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-30775.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="30775" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.124</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'MF2HZ6SRm_2BDDq029M7GPdG_2FFpJhuL3nL0N9TanziyupvcXpXUQfUWWt8sp06t_2BEn4I9PX_2BdVEfPrbNmX6wCN9Q_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>