Next article: ASP Development Example of WAP Simple Mail System (cont.)
With the increasing number of mobile phone users, WAP sites such as springing up quickly, mobile phone mailboxes are constantly appearing in front of people, the author has developed a set of mobile phone mailbox system, but because of time and then have been busy working things, system function has not been strengthened, Today, with the help of IT168 original network open out, and everyone to share, I hope we can exaggerated, strengthen the system function, can be better applied in practice.
Test software: Opera m3gate
Test model: eg730+ Nokia 6681 Moto v3i
Mail component: W3 jmail 4.4
Introduction of WML structure
First of all, we first make a simple introduction to the structure of WML, so that we can better browse the source.
〈?xml version= "1.0"?
〈! DOCTYPE WML public "-//wapforum//dtd WML 1.1//en" "Http://www.wapforum.org/DTD/wml_1.1xml"
〈wml〉
〈head〉
〈access/〉
〈meta..../〉
〈/head〉
〈card〉
Some contents ...
〈/card〉
〈wml〉
We give the simplest example based on the above structure:
〈% @LANGUAGE = "VBSCRIPT" codepage= "65001"%〉
〈%response.contenttype = "TEXT/VND.WAP.WML; Charset=utf-8 "%〉
〈?xml version= "1.0"?
〈! DOCTYPE WML public "-//wapforum//dtd WML 1.1//en" "Http://www.wapforum.org/DTD/wml_1.1xml"
〈wml〉
〈card title= "mail System"
〈p〉
WML Development mail system
〈/p〉
〈/card〉
〈/wml〉
Save the above code as example.asp, directly through the M3gate view, the specific effect as shown in Figure I.
Figure I
"Mail system" this paragraph of text for UTF-8 code, in order to better apply to mobile browsing, the proposed code format using UTF-8, you can download WAP encoder converter to Chinese conversion.
Since our system is developed in ASP language, we need to add the following two pieces of code before the above code snippet:
〈% @LANGUAGE = "VBSCRIPT" codepage= "65001"%〉
Specifies that IIS reads the passed string (form submission, address bar delivery, and so on) in a UTF-8 encoded format, and you can change 65001 to 936 if you need to read in GB2312 format.
〈%response.contenttype = "TEXT/VND.WAP.WML; Charset=utf-8 "%〉
Specifies that the page output format is WML and is encoded as UTF-8
Second, the JMail component function Introduction
W3 JMail is an SMTP component that can be used to send messages and support HTML-formatted messages. You can visit the homepage: http://tech.dimac.net Download this component. W3 jmail Send mail fast, feature-rich and free.
The following are the relevant functions and attributes to be used in the system, and for more detailed information, refer to JMail's official instructions.
1, JMail. POP3
Creating POP3 Objects
Set POP3 = Server.CreateObject ("JMAIL.POP3")
Connect (Username, Password, Server, Port):
Open and connect the POP3 server,
Username: Mailbox User Name
Password: Mailbox Password
SERVER:POP3 Server
Port: Server port number, optional, defaults to 110
Example: Mailbox. Connect "John", "qwerty", "mail.myDomain.com"
Disconnect ():
Close link
Example: Mailbox. Disconnect
Deletesinglemessage (MessageID):
Deletes the message specified by MessageID from the mail server.
Mailbox.deletesinglemessage 1
Messages (): pointer
Returns a collection of message
Set messages = Mailbox. Messages
2, JMail. Message
To create a Message object:
Set Message=server. CreateObject ("Jmail.message")
Silent (): Boolean
If set to True,jmail does not throw an exception error. Jmail.execute () returns TRUE or false based on the action result
Example: Message.silent = True
Charset (): String
Character set, default to "Us-ascii"
Example: Message.charset = "Us-ascii"
From (): String
Sender
Example: message.from= "sn1985boy@sohu.com"
Subject (): String
Send a topic
Example: message.subject= "Testing"
Body (): String
Message body part
Example: message.body= "Congratulations on sending success!"
Mailserverusername (): String
User name
Example: Message.mailserverusername= "* * *"
Mailserverpassword (): String
Password
Example: message.mailserverpassword= "********"
MailDomain (): String
The domain name of the mail server
Example: message.maildomain= "www.sohu.com"
Priority (): Byte
Emergency, defaults to 3,1 as the fastest, 5 for the slowest
Example: message.priority=2
Send (MailServer, enque): Boolean
Send the message. The mail server is a string that describes the name or address of the mail server, and the username and password are optional. When you want to send an authenticated message using the format: Username: password @ mail server
Example:
Message.send ("Mymailserver"), Message.send ("myusername:mypassword@mymailserver.mydomain.com")
Count (): Integer
Return number of messages
Example: i = mailbox. Count
Item (Index): pointer
Returns a Message object
Example: Set msg = Messages.item (0)
Recipients (): pointer
Returns a collection of recipients.
Example: Set Recipients = Msg. Recipients
Attachments (): pointer
Returns a collection of attachments for a message.
Example: Set Attachments = Msg. Attachments
3, Jmail.recipients
Count (): Integer
Returns the total number of recipients in the collection.
Example: i = Recipients.Count
Item (Index): pointer
Returns a specified recipient in the collection.
Example: Set re = Recipients.item (0)
4, Jmail.attachments
Count (): Integer
Returns the total number of attachments in the collection.
Example: i = Attachments.count
Iii. Introduction to the mail system
This mail system includes the landing mail, sends the mail, receives the mail, deletes the mail, replies the mail five functions, the following we have separately introduced to each function, and accompanying the source code, this tutorial all pictures for m3gate test screenshot.
1) Landing mail
Figure II
As we can see from figure II, the landing page includes a form that contains two text boxes and a Send button, so how do you submit the form in the WML language? First, let's look at some of the form elements in the WML language: 1, input elements
〈input name= "User" title= "label" type= "type" value= "value" default= "default" format= "specifier" emptyok= "false|true" Size= "n" maxlength= "n" tabindex= "n"/〉, which is used to enter text, except that the Name property is necessary and optional.
*name Property: Specifies the name of the variable used to store the input text.
*title Property: The name of the input box can also be used as the option name in the Profile Card page.
*type property: The default value is text, and if you select password, the input data appears as *.
*value attribute: The syntax and behavior are equivalent to the following default property,
*default Property: Specifies the default value for the input box, which is the Name property that specifies the default value for the variable, which is not valid when the user enters a new value, and if the value does not conform to the following format property, the phone also ignores the default value.
*format property: Used to format the input data, the available tags are as follows, used in the form of "one digit mark" and "* mark", which represents n-tagged characters, such as 3X, which represents any one (less than the value of the MaxLength property) marker characters.
Tag description
A any symbol or capital letter (excluding numbers)
A any symbol or lowercase letter (excluding numbers)
N any number (excluding symbols or letters)
X any symbol, number, or capital letter (cannot be changed to lowercase letters)
x any symbol, number, or lowercase letter (cannot be changed to uppercase letters)
M any symbol, number, or uppercase letter (can be changed to lowercase letters) or more than one character, default to uppercase
m any symbol, number, or lowercase letter (can be changed to uppercase letters) or multiple characters, default to lowercase
*maxlength Property: Specifies the maximum length of characters that a user can enter, with a maximum limit of 256 characters.
*emptyok property: Indicates whether the user can fill in the input box, default to False.
*size Property: The input box displays the length and is not currently supported.
*tabindex property: This is similar to the choice in which the focus falls when you press the TAB key in an HTML form, and the value determines the order in which the number is left behind. Not currently supported.
Example:
〈input type= "text" title= "username" name= "user" maxlength= "50"/〉
2. Do element
Do is one of the most valuable elements in the WML language, providing a common way for users to "act" on the current card.
List of properties:
*type property: Tells the browser the intent of the action.
WML declares a total of 9 types of actions, the most common type of action is "accept" and "option".
1, accept, accept, confirm
2, prev, returns the URL in the previous history stack
3, help, request assistance
4, reset, clear or reset the state
5, options, according to the function of the current page settings.
6, Delete, remove select entry
7, Unknow, equivalent to a blank string
8, vnd.*. Vnd.* and other different case combinations [vv][nn][dd].*. This type is defined as Vnd.cotype, which activates a specific feature that is customized by the vendor or user's browser, where co is the abbreviation for company name.
9, x-* and x-*. Extension types that are not currently used in WML.
*label Property: Sets the button caption, showing the location of the screen defined in the browser, different browsers to display different locations. If you do not set a caption, the button appears in the default format of the browser, and the default format is different for different browsers.
* Name property: Button name, you can use the card-level action to overwrite the same name on the template action, the new task to give those actions.
*optional property: To define whether a button is displayed and is ignored by the browser when set to True
Example:
〈do type= "Accept" label= "send" optional= "false"
{Content}
〈/do〉
3, Go Element
Used to instruct the browser to display the specified URL, including the first card of the deck or the specified card. The syntax is as follows:
〈go href= "url" sendreferer= "false|true" method= "Get|post" accept-charset= "CharSet"
〈postfield name= "name" value= "value"/〉
〈setvar name= "name" value= "value"/〉
〈/go〉
Where the href attribute is required and the other is optional.
*sendreferer property: Whether the URL of the current page is passed, and the default value is False.
*method property: As with the method property of form form in HTML, specifies whether the form is submitted in Get or post, the default value is get, but if method is not specified but there is a 〈postfield〉 between 〈go〉〈/go〉, The mobile phone is automatically delivered in post mode.
*accept-charset property: You can override the character set specified in the HTTP header and write multiple character sets, such as accept-charset= "Utf-8,us-ascii, iso-8859-1".
The 〈postfield name= "name" value= "value"/〉 can be viewed as 〈input type= "HIDDEN" name= "value" in the HTML form form, which can be passed to the specified URL with a " Variable name/value "form of data. Both the name and value properties are required. Note that only the variables here are used to submit to the CGI program.
In addition to 〈postfield〉, one or more sentences can be added between 〈go〉 and 〈/go〉 〈setvar name= "name" value= "value"/〉, which means that when an event is triggered, the variable is assigned a value.
Example:
〈go href= "main.asp" method= "post" accept-charset= "Utf-8"
〈postfield name= "User" value= "$ (user)"/〉
〈postfield name= "pwd" value= "$ (pwd)"/〉〈/go〉
〈/do〉
Mail Login interface Source: index.asp
〈% @LANGUAGE = "VBSCRIPT" codepage= "65001"%〉
〈%response.contenttype = "TEXT/VND.WAP.WML; Charset=utf-8 "%〉
〈?xml version= "1.0" encoding= "Utf-8"?
〈! DOCTYPE WML public "-//wapforum//dtd WML 1.1//en" "Http://www.wapforum.org/DTD/wml_1.1.xml"
〈wml〉
〈card title= "Mailbox Landing"
〈p align= "Center"
Welcome to Sohu-wap-mail〈/p〉
〈p〉
User name:
〈input type= "text" title= "username" name= "user" maxlength= "30"/〉
〈br/〉 Password:
〈input type= "password" title= "password" name= "pwd" maxlength= "30"/〉〈br/〉
〈do type= "Accept" label= "send" optional= "false"
〈go href= "main.asp" method= "post" accept-charset= "Utf-8"
〈postfield name= "User" value= "$ (user)"/〉
〈postfield name= "pwd" value= "$ (pwd)"/〉〈/go〉
〈/do〉
〈/p〉
〈/card〉
〈/wml〉
2) Mail Main Page
The main function of the Mail homepage is to verify that the user name and password passed through the landing page are correct, and if it is correct, display the relevant mail action link (figure IV), or the password error will be required to re-enter (figure III). Because some mobile devices do not support jumps, programs try to avoid using jump statements.
Figure III (landing failure) Figure four (landing success)
Mail home Page source code: main.asp
〈% @LANGUAGE = "VBSCRIPT" codepage= "65001"%〉
〈%response.contenttype = "TEXT/VND.WAP.WML; Charset=utf-8 "%〉
〈?xml version= "1.0" encoding= "Utf-8"?
〈! DOCTYPE WML public "-//wapforum//dtd WML 1.1//en" "Http://www.wapforum.org/DTD/wml_1.1.xml"
〈wml〉
〈card id= "main" title= "Sohu-palm-mail platform"
〈p〉
〈%
On Error Resume Next
User=request ("User")
Pwd=request ("pwd")
Set POP3 = Server.CreateObject ("JMAIL.POP3")
Pop3.connect user,pwd, "http://pop3.sohu.com"
POP3. Disconnect
If Err.number〈〉0 Then
Response.Write ("Login error, please check the username password is correct!") 〈br/〉 ")
Response.Write ("〈a href= ' index.asp ') re-landed 〈/a〉〈/p〉〈/card〉〈/wml〉")
Response. End ()
End If
Response.Write ("Welcome" &user& "@sohu. com〈br/〉")
%〉
〈a href= "email_title.asp?user=〈%=user%〉&pwd=〈%=pwd%〉" Inbox 〈/a〉〈br/〉
〈a href= "send.asp?user=〈%=user%〉&pwd=〈%=pwd%〉" Outbox 〈/a〉〈br/〉
〈a href= "index.asp" to land again 〈/a〉〈br/〉
〈/p〉
〈/card〉
〈/wml〉
Note:
〈a href= "email_title.asp?user=〈%=user%〉&pwd=〈%=pwd%〉" Inbox 〈/a〉
Because some mobile devices do not support session, in order to better application, so the use of URL parameter transmission, unfortunately, this is not a high security, in order to improve security, we recommend that the parameters of plaintext encryption after the transmission, in the receiving page in doing the corresponding decryption processing, of course, if you have any better way, Please also send an email to point out, thank you.