Building a Robust Web Based Email Client (Webmail) Using the ip * Works! ADO.NET DATA Provider (Chinese)

xiaoxiao2021-03-06  51

In 2004, the software introduced in the world's Internet development: Internet ADO.NET Provider. Some of the most often used objects from popular IP *! The toolbox includes a new product called IP * WORKS! ADO.NET Provider, allows you to use the database developers more familiar with these protocols in a way. In order to receive all messages from your inbox, you can choose Select * from Inbox. Read the latest RSS you can select * from feed. For e-mail, Insert a new row into the outbox table.

In this article, I will talk about the Characteristics and use of Provider, and along the way I will build the IMAP and POP of the ability to Webmail with the minimum number of code interfaces. You can also download a sufficient sample project here.

Provider overview

During the start of the process, the protocol is IMAP, POP, SMTP, NNTP, and RSS. Other people will be increased, like WebDAV (also name httpmail), LDAP, etc. IP * Works! ADO.NET Data Provider makes Internet capabilities quickly and easy - there is no need to be familiar with the internal operation of the protocol.

You are familiar with DBConnection, DBDataAdapter and dbcommand objects. Now let me introduce ipworksconnection, ipWorksDataAdapter, and ipWorksCommand objects. In addition to certain things that have occurred on, they work according to the same familiarity - continuously improve from one server rather than the database. This is a short description of different objects in the provider. In this article, I will fall into more details and display how to use each.

Ipworksconnection

IpWorksConnection object management is a Connection of some servers, whether it is IMAP, POP, HTTP, SMTP, or NNTP server. IpWorksConnection can be explicitly opened, or ipWorksDataAdapter can manage automatic (only when necessary) Connection.

IpworksDataAdapter

IPWorksDataAdapter is just like the DataAdapter you are accustomed to. It will allow you to perform commands in DataSet or DataTable. If a connection is not disclosed, a person will be automatically established in order to carry out necessary surgery.

IpworksCommand

IpWorksCommand object describes a SQL command: select, insert, delete, or constantly improve.

IpworksCommandbuilder

The IPWorksCommandBuilder object will automatically generate insert, delete, and constantly improve the command that is suitable for ipWorksDataAdapter, give a certain selection command.

Connection

First of all, I will start I will install ipworksconnection, so I need to determine this Connection line. In order to form this Connection line, only the characteristics of all Connection are specified when all of the CONNECTION is separated by value. A Connection feature is required in all instances of IPWorksConnection: Agreement. Protocol Connection Properties Specifies the Internet protocol to be used for this Connection. Depending on the protocol, other Connection features will be applied. For example, if I use an IMAP protocol, in order to connect, I will need to specify MailServer, users, and password features. If I use the RSS protocol, I will need at least the URL. This is some examples: ipWorksconnection ipwconnection1 = new ipworksconnection ("protocol = IMAP;

MailServer = MyServer; user = myusername; password = mypassword ");

Ipworksconnection ipwconnection2 = new ipworksconnection ("protocol = rs;

URL = http://slashdot.org/ ");

Ipworksconnection ipwconnection3 = new ipworksconnection ("protocol = nntp;

Newsserver = msnews.microsoft.com ");

Ipworksconnection ipwconnection4 = new ipworksconnection ("protocol = SMTP;

MailServer = myserver ");

ipWorksconnection ipwconnection5 = new ipworksconnection ("protocol = pop;

MailServer = MyServer; user = myusername; password = mypassword ");

For a full directory of a connection line character, please teach the documentation of IP *! ADO.NET Data Provider.

My goal is to build webmail applications - so my Connection line will need to accept a network form in the user to specify their username, password, and so on. I will accept the value of a web form. My Connectionstring will look like this:

ipWorksconnection1 = new ipworksconnection (string.format ("protocol = {0};

MailServer = {1}; user = {2}; password = {3}; ",

RBLPROTOCOL.SELECTEDITEM. Value, TXTSERVER.TEXT,

TXTUSER.TEXT, TXTPASS.TEXT);

Column

For the next step, I will establish a data harmonizer, and make it command:

IpWorksDataAdapter iPworksDataAdapter1 = new ipworksdataadapter ();

When the command is executed, each command will be related to a Connection that should be used. For webmail applications, I need to choose to use an IMAP Connection and a POP Connection. Since my Connection line allows the user to choose to use IMAP or POP, I just need to guarantee that my selection command will be valid for any of the two. Each protocol has its effective column and Tables's own directory. For example, the POP protocol supports the following columns:

MessageID

MessageFrom

MessageSubject

MessageText

MessageDate

Messagecc

MessageHeaders

MessageReplyto

MessageSize

Messageto

Imap, as a more distinctive agreement, supports more columns. In addition to all of the POPs provided above, IMAP also provides the following columns:

MessageFlags

MessageDeliveryTime

Messagesender

Messagebcc

MessageinReplyto

MessageNetid

MessageContentType

MessageContenTencoding

In order to make the same selection as any of the two protocols, I will only limit my own columns in the columns supported by the two protocols. Choose, I use different selection statements to depends on those protocols, or I can use a choice * Get all columns.

ipworksdataadapter1.selectcommand = new ipworkscommand ("SELECT MessageID,

MessageFrom, MessageSubject, MessageDate, Messagesize from Inbox,

Ipworksconnection1);

Tables

The above selection command gets some columns from the inbox tables. But what other Tables is available? The available tables depends on the protocol. For POP, the inbox is the only Tables there. Similar to RSS has only one Tables (supply itself). But for other protocols like IMAP and NNTP, there are multiple Tables.

For the IMAP protocol, Tables is just the name of the IMAP mailbox (folder) you are interested in. Therefore, the inbox is usually working for POP and IMAP, but IMAP has additional capabilities above the POP, so if your IMAP inbox has a folder called "TODO", you will have a "Inbox.todo" TABLES.

A special tables, "Schematables", can be used to get a tables named TABLES. This will use the IMAP protocol to get a directory for all mailbox folders, and get a directory of all organizations with a special press meter with a special press meter. In order to use Schematables, you will use the following selection statements:

"SELECT * from information_schema.taables"

Fill a data sheet

For this article, I will use the inbox Tables for POP and IMAP sticking. At this point, we have almost handled the foundation. We have a Connection, there is a editor of the selection command. All left sides will be filled with a table.

ipWorksconnection1 = new ipworksconnection (string.format ("protocol = {0};

MailServer = {1}; user = {2}; password = {3}; ",

RBLPROTOCOL.SELECTEDITEM. Value, TXTSERVER.TEXT,

TXTUSER.TEXT, TXTPASS.TEXT);

IpWorksDataAdapter iPworksDataAdapter1 = new ipworksdataadapter ();

ipworksdataadapter1.selectcommand = new ipworkscommand ("SELECT MessageID,

MessageFrom, MessageSubject, MessageDate, Messagesize from Inbox,

Ipworksconnection1);

System.Data.DataTable DataTable1 = new system.data.dataable ();

ipworksdataadapter1.fill (DataTable1);

Webmail - Login

In this webmail application - I am about online communication (IMAP, POP, SMTP) does not have to think that I will use * Works IP! ADO.NET Provider. I do must consider meeting management and data. I need to provide a registration number mechanism, so I will add a formal verification section to Web.config:

Then I will implement the form of registration number (login.aspx). The registration number will contain the TextBoxes users to enter the necessary users, passwords, and server information. It will also contain RadiobuttonList to select POP or IMAP and of course a "login" button. When this registration number button is clicked, an ipWorksConnection object will be created using user input.

When I use ipWorksDataAdapter, when it is asked, it can automatically open a connection instead of I keep the Connection. However, since the user will use postbacks in the meeting's life, the user is logged in, I will keep the Connection by adding the IPWorksConnection instance to the meeting, and manually open it, until the meeting ends or until the user is logged out.

RedirectFromLoginPage is back in our results where the URL (for example, default.aspx) is finally after all this.

Private Void Blogin_Click (Object Sender, System.EventArgs E)

{

ipWorksconnection1 = new ipworksconnection (string.format ("protocol = {0};

MailServer = {1}; user = {2}; password = {3}; ",

RBLPROTOCOL.SELECTEDITEM. Value, TXTSERVER.TEXT,

TXTUSER.TEXT, TXTPASS.TEXT);

Session.clear ();

Try

{

Ipworksconnection1.open ();

Session.Add ("ipworksconnection", ipworksconnection1);

Formsauthentication.RedirectFromLoginPage (txtuser.text, false);}

Catch (Exception EX)

{

Lerror.Text = ex.Message;

}

}

Browse emails

In Default.aspx, I will use DataGrid to display emails in this inbox. On the page _ a lot of this homepage, I will check if there is a DataView object on the meeting. If this is not there, I know that this is the first time that the meeting was recorded, and I implemented some of the measures to install these meetings:

Causes an ipWorksconnection instance and set it is equal to the one in the meeting (established in login.aspx).

Create ipWorksDataAdapter and select Command Select the message column I want.

Filled with ipWorksDataAdapter with DataTable.

Determine a DataView object equivalent to the default DataTable of the newly filled DataTable and add new DataView to the meeting.

DataView has existed in the meeting if I know that these steps are not implemented, and DataBind is really changed to DataGrid.

Private Void Page_Load (Object Sender, System.EventArgs E)

{

DataView DV = (DataView) Session ["MessageView"];

IF (DV == Null)

{

DataTable DT = New DataTable ();

IpWorksconnection DataConnection =

(IpWorksconnection) session [ipworksconnection];

IpworksDataAdapter DataAdapter = new ipworksdataadapter ();

DataAdapter.selectCommand = new ipworkscommand ("SELECT MessageID,

MessageFrom, MessageSubject, (Datetime) MessageDate,

(int) Messagesize from Inbox ", Dataconnection);

DataAdapter.Fill (DT);

DV = DT.DEFAULTVIEW;

Session.Add ("MessageView", DV);

}

DGMESSAGES.DATASOURCE = DV;

DGMESSAGES.DATABIND ();

}

Give a gift

At this point, the user has logged in and has a boundary of the DataGrid including information about the email. Notice that the selection is used to get only MessageID, MessageFrom, MessageSubject, MessageDate, and Messagesize. I didn't choose MessageText. This is the best news that the content of the real message may be huge (if you say the big attachment, or many emails). After a user has clicked a special message, I will change only MessageText.

Building a way a user clicks a message, I will make some of the pillars of the DataGrid Hyperlink pillars, format hyperlinks creates MessageID that includes the messages they have clicked. For example, the theme column The body value will be tied to the "MessageSubject" column, but its URL field will be "MessageID". The line of the URL form column will "Read.aspx? UID = {0}". This gives us the ability to contact us in this column and the ability of the read.aspx. Uid QueryString variable value will come from the selected row MessageID pillars. I can certainly do the same, date, and / or size column that I want. Read email

Read.aspx contains those emails that will display content, and the first item of this important message is as good as, give, theme, etc.

On the page _ installed, I chose those columns will be completely from the previous, except for this MessageText column. This time, I will like this to use the place to choose only those pillars from MessageID where one person passes inside QueryString.

Private Void Page_Load (Object Sender, System.EventArgs E)

{

IpWorksconnection DataConnection =

(IpWorksconnection) session [ipworksconnection];

IpworksDataAdapter DataAdapter = new ipworksdataadapter ();

DataAdapter.selectCommand = new ipworkscommand ("SELECT MessageID,

MessageFrom, (String) Messageto, MessageSubject,

(Datetime) MessageDate, (int) Messagesize, MessageText from Inbox

WHERE MessageId = " Request.QueryString [" UID "], Dataconnection;

DataAdapter.Fill (DT);

THIS.DATABIND ();

}

During the design time, I have the characteristics of the boundary textboxes in the form and their respective pillars in the DataTable. In the name txtMessage, I set one of the textbox's databindings on the table containing the content of the message body. I determine the custom-bundled texture to represent the DT.ROWS representation [0] ["MessageText"]. I will also in this form ( LSUBJECT, LTO, LFROM, and the like are determined to determine the DataBindings of other tags. In this way, I am called DataBind _ installed in the page, all control value will be automatically lived from DataTable.

DataBinding Since those LSIZE tags, I combine it and the function called FormatSize will be changed to it in this Messagesize column. With this method, I can format the dimensional body in this way.

Public Static String FormatSize (Object O)

{

INT i = convert.toint32 (o);

String [] suffix = {"b", "kb", "mb", "gb"}

INT j = 0;

While (i> 1024 && j <4) {

i = I / 1024;

J ;

}

Return (i " SUFFIX [J]);

}

Mail

Email email, and about DataTable - send a new message to follow, you should insert a new row.

A way to do this, open Connection, and called IPWorksCommand EXECUTEREADER methods. Use the insert command to determine the purpose of the parameter series command to give their respective columns from the insert to command their own and match value, like the example below:

Private void bsend_click (Object Sender, System.EventArgs E)

{

Ipworksconnection dataconnection = new ipworksconnection

String.Format ("protocol = SMTP; mailserver = {0};",

GetConnparam ("MailServer"))))

Try

{

Ipworkscommand ipworkscommand1 = new ipworkscommand ("INSERT INTO OUTBOX

(Sendto, Subject, Messagetext, MessageFrom), Dataconnection;

(IDataParameter) ipworkscommand1.parameters [0]). Value = txttto.text;

(IDataParameter) ipworkscommand1.parameters [1]). Value = txtsubj.text;

(IDataParameter) ipWorksCommand1.Parameters [2]). Value = txtmsg.text;

(IDataParameter) ipWorksCommand1.Parameters [3]). Value = txtFrom.text;

DataConnection.open ();

Ipworkscommand1.executeReader ();

}

Catch (Exception EX)

{

Lerror.Text = ex.Message;

}

Finally

{

DataConnection.Close ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-80840.html

New Post(0)