Use C # production "mail express delivery"

xiaoxiao2021-03-06  44

Author:

Cai Xiaomei

Zhangzhou Teachers College 082 Mailbox

Download source code

I. Introduction

There is a "mail express delivery" in the new version of Foxmail. I don't know how to use it first, and later I know that I want to set the "IP address of the local DNS server" on "Tools -> System Options".

I feel that this new feature is quite easy to use. You don't need to pass the SMTP proxy, you can send mail directly through the mail switch to your mailbox. I want to implement this function in VC at the beginning of the summer vacation. After using the Iris seat, there is a MX8.263.NET in the program to send the mailbox, I don't know what this is, so I will have. Later, I thought this is the 263.NET MX record host. The principle of expressive express delivery is to send data to this host.

Run the NSLookup program:

SET TYPE = MX

263.net

Yes, yes, get the results:

Non-Authoritative Answer:

263.NET MX preference = 10, mail exchanger = mx06.263.net

263.NET MX preference = 10, Mail Exchange = mx08.263.net

263.NET MX preference = 10, Mail Exchange = mx09.263.net

263.NET MX preference = 10, Mail Exchange = mx11.263.net

263.NET MX preference = 10, mail exchanger = mx12.263.net

263.NET MX preference = 40, mail exchanger = mx03.263.net

263.NET MX Preference = 10, mail exchanger = mx01.263.net is not wrong. This is this. Later, I didn't know how to achieve NSLOOKUP's function, I gave up and learned about half a month of C #. Later, I found some related documents online. A few experiments. Take my development process to share, I wrote the tutorial document. So, if you don't standardize, please bear it. The domain name, mailbox and IP involved in this article are true.

Second, the principle of DNS protocol

I think that if you want to be a good network software programmer, you must read the RFC documentation. Because this article is a fans for most broad program enthusiasts, I try to write from the details. If the master, you can skip this part.

Related RFC Documents of the DNS Agreement:

RFC1034- "Domain names - Concepts and facilities"

The computer used on the RFC1035- "Domain Names - Implement and Specification" online, such as 220.162.75.1, called the IP address, is identified by a computer. And if you visit a computer accessed by entering such a stuff, isn't it too terrible? To have a good stuff like DNS, use the IP address to indicate it, when we enter http://zssy.com in the browser, the browser doesn't know where to get it, so it will Set up the DNS server query zzsy.com domain name. The DNS server will look for your own record library, and if you don't find it, turn to the previous DNS server for query (forwarding request). Tell your browser to find the IP. The record type of the browser query is a record. RFC1035 Documents Define 16 record types in page 11, and common A (address) record, CNAME (alias) record, MX (mail exchange) record. We must care about MX records. The process of queries is generally: the customer sends a UDP packet to the 53 port of the DNS server, and the DNS server is processed and processes the results records still returned in the form of UDP packets.

The general format of this UDP message:

---------------------

| Packet head |

---------------------

| Question | Query part of the server

---------------------

| Answer | Resource Record of Server Reply

---------------------

| Authorized | Authoritative resource record

---------------------

| Extraordinary | Extraordinary Resource Record

---------------------- In addition to the packet head is fixed 12 bytes, the length of each part is unordered byout.

We care about the news head, the problem, and answer these three parts.

Among them, the format of the newspaper:

1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

- - - - - - -

| ID |

- - - - - - -

| Qr | opcode | AA | TC | RD | RA | Z | RCODE |

- - - - - - -

| QDCOUNT |

- - - - - - - | ANCOUNT |

- - - - - - -

| Nscount |

- - - - - - -

| Arcount |

- - - - - - - - Good Guy, what ghost paint!

One of the top is the number identifier, 0-15 (note that the 10-15 behind the back is in the form of up and down, and I didn't understand it at the beginning.

Next is:

ID: 16 bits, 2 bytes. The number of this message is specified by the client. The DNS reply is taken on this identifier to request a request for the corresponding correspondence.

QR: 1 bit, 1/8 bytes. 0 represents the query, 1 generation DNS reply

Opcode: 4 digits, 1/2 bytes. Indicates the type of query: 0: Standard query; 1: reverse query; 2: server status query; 3-15: Not used.

AA: 1 bit, 1/8 bytes. Whether authority reply.

Tc: 1 bit, 1/8 bytes. Because a UDP message is 512 bytes, the bit indicates whether the exceeded portion.

RD: 1 bit, 1/8 bytes. This bit is specified in the query and the same time is the same. Set to 1 Indicate the server for recursive query.

RA: 1 bit, 1/8 bytes. Returns the specified by DNS reply, indicating whether the DNS server supports recursive query.

Z: 3 digits, 3/8 bytes. The preserved field must be set to 0.

Rcode: 4 digits, 1/2 bytes. The return code specified by the reply: 0: No error; 1: Format error; 2: DNS error; 3: Domain name does not exist; 4: DNS does not support this type of query; 5: DNS refuse query; 6-15: Reserved field .

QDCount: 16 bits, 2 bytes. An unsigned number indicating the number of query records.

ANCOUNT: 16 bits, 2 bytes. An unsigned number indicates the number of reply records.

Nscount: 16 bits, 2 bytes. An unsigned number indicates the number of authoritative records.

Arcount: 16 bits, 2 bytes. An unsigned number indicates a number of exception records.

Each query resource record format:

1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

- - - - - - -

| | / QNAME /

/ /

- - - - - - -

| Qtype |

- - - - - - -

| Qclass |

- - - - - - QNAME : Not long, indicating the domain name to query. (The boxes of both sides are used to indicate unordered length)

Qtype: 2 bytes, according to RFC1035 and NSLOOKUP help documents, I define the following enumeration types:

Enum querytype // The resource record type of Query.

{

A = 0x01, // Specify the computer IP address.

NS = 0x02, / / ​​Specifies the DNS name server for the naming area.

MD = 0x03, // Specify the mail receiving station (this type is outdated, use MX instead)

Mf = 0x04, // Specify the mail transfer station (this type is over time, use MX instead)

CNAME = 0x05, / / ​​Specifies the specification name for the alias.

SOA = 0x06, / / ​​Specifies "starting authority" for the DNS area.

MB = 0x07, // Specify the mailbox domain name.

MG = 0x08, // Specify a member of the mail group.

MR = 0x09, // Specify the mail rename domain name.

NULL = 0x0a, // Specify an empty resource record

WKS = 0x0b, // Describe known services.

PTR = 0x0c, // If the query is an IP address, specify the computer name; otherwise specify a pointer to other information.

Hinfo = 0x0d, // Specifies the computer CPU and the operating system type.

Minfo = 0x0e, // Specify a mailbox or mailing list information.

MX = 0x0f, // Specify a mail switch.

TXT = 0x10, // Specify text information.

UINFO = 0x64, // Specify user information.

UID = 0x65, // Specify the user identifier.

GID = 0x66, // Specify the group identifier of the group name.

Any = 0xFF // Specify all data types.

}; Qtype: 2 bytes. According to the help documentation of RFC1035 and NSLOOKUP,

I define the following enumeration type:

Enum queryClass // Specify the information of the protocol group.

{

IN = 0x01, // Specify the Internet category.

Csnet = 0x02, // Specify the CSNet category. (Out of time)

CHAOS = 0x03, // Specify the chaos category.

Hesiod = 0x04, // Specify Mit Athena HesioD category.

Any = 0xFF // Specifies any previously listed wildcards.

}; A, MX, CNAME in Qtype is common, and IN in QClass is common. Each reply record format: 1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

- - - - - - -

| | |

/ /

/ Name /

| | |

- - - - - - -

| TYPE |

- - - - - - -

| Class |

- - - - - - -

| TTL |

| | |

- - - - - - -

| RDLENGTH |

- - - - - - - - - |

/ RDATA /

/ /

- - - - - - NAME : Reply to the domain name of the query, not long.

TYPE: The type of reply. 2 bytes, synonymous with queries. Indicates the type of resource record in RDATA.

Class: Reply to the class. 2 bytes, synonymous with queries. Indicates the resource record class in RDATA.

TTL: Survival time. 4 bytes, indicating that the resource recorded in RDATA is recorded in the cache.

Rdlength: Length. 2 bytes, indicating the length of the RDATA block.

RDATA: Resource Record. Undefined, depending on Type, this record is different, usually one MX record is composed of a 2-byte indicated a priority value of the mail switch and an unregistered mail exchanger name. This describes the combination of names. The name consists of a plurality of identity sequences, and the first byte of each identifier sequence illustrates the length of the identifier, and then uses a ASCII code to represent characters, and multiple sequences are later indicated by byte 0. If the length of the first character of one of the identification sequences is 0xc0, it means that the next byte indication is not an identifier sequence, but instead indicates the offset position in the next portion within the receiving package.

For example, BBS.ZZSY.com. Separate BBS, ZZSY, COM. The length of each part is 3, 4, 3

In the form of the DNS packet, like 3 B B S 4 Z z y 3 C O m 0

If there is a name of 4 Z Z Y 3 C O m 0 in the 12th byte location in the package.

It is possible to: 3 B B S 4 Z z y 0xc0 0x0c.

Third, DNS protocol instance explanation

Said so many theoretical fits, there may be two big heads. Or use an example method to explain it. I chose the famous webcape and protocol analysis tool Iris 4.05, you can download from my site:

Http://itboy.cn/data/iris405full.rar

Run IRIS, click on the Filters selection port tab of the menu to use the 53 port after determination. Click on the green run icon on the IRIS toolbar for listening. Run the NSlookUp program in Windows. Enter the following command:

SET TYPE = MX

Then return to the NSLookUP program. Enter the command:

Yahoo.com.cn

Get up

Yahoo.com.cn mx preference = 20, mail exchanger = mx5.mail.yahoo.com

Yahoo.com.cn mx preference = 10, mail exchanger = MTA-V1.MAIL.VIP.CNB.YAHOO.com

Such two MX resource records are recorded. At this time, the IRIS Cut is shown in the figure: The current illustration shows the packet, which is a message replying from DNS. The first message is a query message, which is much simpler than the reply packet. Therefore, if you analyze the reply packet, the query message believes that smart is as easy as you can make it easy. The red portion of the figure shown in the figure is a DNS packet, and the data content on the upper side is the MAC Joint, PPP Protocol, IPv4 Protocol Pack and UDP Protocol Pack. These packages are not within the scope of this article, not paying attention. (Insert some nonsense: Click on the entry displayed in the left tree of IRIS, not necessarily reflected in the packet on the right, I don't know, I don't know at the beginning, and analyze it according to the indication of it, analyze it. For a long time, I don't know what to say. The analysis of the package is to study this program in this program. In the past two, the online class did not listen to the online class of our college, and weird. , 咋 叫 叫 教 教 教 专 专 专 专 专 专 专 专 专 专: 地 地 专: 地For the convenience of explanation, I handled some of the DNS protocols in the bag, as shown below: where the red portion is the header, the blue is the first resource record of the reply, the golden is the reply Two resource records. Others don't have the authority record, extra record, don't analyze it. Red part: 0th byte, the first byte 00 03 identifies an ID. The 2nd byte, the third word 81 80 is chemically binary form 1000 0001 1000 0000 qr (0) is 1 reply to the reply packet. OpCode (2-5) represents a standard query. AA (6) indicates a non-authoritative query. TC (7) is 0 indicates that no more than 512 bytes of packets do not truncate. RD (8) is 1 indicating that the NSLookUP program indicates that the DNS is recursive. RA (9) is 1 to represent DNS support recursive query. Z (10-12) Reserved Field Rcode (13-16) to 0 indicate that the query does not perform in error 4 bytes, the 5th byte 00 01 indicates that the number of resource records of the query is 1, the 7th byte 00 02 Indicates that the number of resource records of the reply is 2 8th bytes, and the 9th byte 00 06 indicates that the number of authoritative resource records is 6 10th bytes. The 11th byte 00 04 indicates that the number of additional resource records is 4 and then arrived. Blue section, the resource record section of the query: The domain name is queried at the beginning. Start 05 The five bytes of the rear are sequence characters, turn the 79 61 68 6F 6f to the ASCII code to arrive with Yahoo to 03 means the three bytes of the rear side are sequence characters, turn the 63 6F 6D to the ASCII code to arrive at 02 Indicates that the two bytes of the rear are sequence characters, and turn 63 6e to the ASCII code to the CN arrival 00. The whole string is used. Connection, that is,: Yahoo.com.cn Next two byte 00 0f indicates that the query type is 15, that is, the MX record query. Next, the two bytes 00 01 indicate that the query class is 1, which is connected to the Internet. The DNS packets in the first package in the IRIS package contain only red lines and blue lines, and the analysis methods are the same. No longer. Green section, the first resource record section of the reply: At the beginning of the domain name of the query, the first byte c0 represents compression, the next bit is the offset byflock. Next, 0C represents the first byte of the blue of the entire package, that is, the first byte of the blue.

Then, the analysis is the same as that of the upper side, and then the domain name yahoo.com.cn is then returned, and the 3-4 byte 00 0f in the next byte green package indicates that the query type is 15, that is, the MX record query. Then the next 5-6 bytes 00 01 indicate that the query class is 1, which is connected to the Internet. Then the next 7-10 bytes 00 00 05 95 is evolved as evolution equal to 1429 seconds. That is, the cache time is 23 minutes and 49 seconds. Then 11-12 byte 00 16 indicates that the data portion recorded in this resource is 22 bytes. That is, the number of bytes left. 22 bytes starting from 13 bytes to the data part of the MX record. This section is formatted to two bytes of mail exchanger priority, unregulated mail switch name. Section 13-14 Byte 00 14 indicates that the priority value is 20, and then from 15, it is a mail switch name, according to the blue domain name analysis method, obtain mx5.mail.yahoo.com (said bytes said in this paragraph is The relative position in the green block, not the absolute position of the entire DNS package) The squares of the golden blocks are similar to the green, but there is a difference that looks at the mail excitation name of the golden bag. From the absolute position of the package, the 78th (the figure in the figure is bidding the purple 78) begins to be the email switch name. We have analyzed, get MTA-V1.MAIL.VIP.CNB, then 0xc0 is then compressed, and then the next offset is 0x0c and jumps to the 12-byte of the package to get Yahoo.com.cn. The entire combination is the second resource record name: mta-v1.mail.vip.cnb.yahoo.com Run with NSlookup: Yahoo.com.cn MX preference = 20, mail exchanger = mx5. Mail.yahoo.com

Yahoo.com.cn mx preference = 10, mail exchanger = MTA-V1.MAIL.VIP.CNB.YAHOO.com

the same. I hope this energy can help network enthusiasts learn the package analysis method. Analysis of programming points of MX record query in our current DNS.

Fourth, DNS query MX record programming program analysis

Foxmail 5.0 email has a very rubbish place where you are unable to automatically get the local ISP DNS server, you need to use the user's manual input, I think it is because the limit of the API or the foxmail development group did not think of the method or other I know what I know. It is easy to use WMI in C #, it is easy:

String [] DNSES;

ManagementClass MC = New ManagementClass ("Win32_NetworkAdapterConfiguration);

ManagementObjectCollection moc = mc.getinstances ();

// Enumerate all the network cards on the current machine

Foreach (ManagementObject Mo in MoC)

{

IF (Bool) Mo ["iPenabled"])

{

DNSES = (String []) Mo ["DNSSERVERSEARCHORDER"];

IF (DNSES! = NULL)

{

DNSSERVER = DNSES [0]; // uses the first found DNS server.

}

}

} Of course, you will not forget to join the reference to System.Management in the project -> add reference? Put this in the static constructor of the DNSQuery class. There is also a custom MXRecord structure that stores information for MX resource records.

Struct Mxrecord

{

Public String Domain; // Domain Name

Public querytype querytype; // Query type public queryclass queryclass; // query class

Public timespan livetime; // Survival time

Public int datalength; // The length of the resource part,

// The number of bytes of the resource indicating the priority and name of the mail server.

Public int preference; // Priority value, the smaller the value, the more preferred.

Public String Name; // Mail Exchanger Name

} Make two bytes into an INT16 integer cannot be used in the BitConverter class because it is different from the DNS server. Therefore, it is displaced with the << method.

Others don't say, in the DNSQuery class of the program, I made a detailed code annotation. If you have some development experience, it should be easy to understand. If you have any questions, please contact me. I will help you with your energy and ability.

V. Analysis of foxmail express delivery data

1. Run IPConfig / ALL

Record the first IP address of the resulting DNS Servers.

2, or run iris. Set Filters as SMTP, 25 ports. Run to listen.

3. Run FoxMail 5.0, "Mail Express" tab within the tool -> system setting Set the domain name server 1 as the just IP address.

Click "Write" and write it with the format of the text file.

Recipient: DreamChild@263.net

Cc:

Theme: Hello Dreamchild, take the liberty to fight

content:

Dear Mr. Dreamchild:

This is an email.

Attachment: (Add mm.gif and instructions. TXT two files. In order to ensure the integrity of this tutorial, these two additional stuff also put it in the package.)

4, stop Iris after completion, point the decode of its menu bar to get the following:

220 Welcome To Coremail System (with Anti-spam) 2.1 for 263 (040326)

Helo DreamChild

250 mta6.x263.net

Mail from: <>

250 ok

RCPT TO:

250 ok

Data

354 End Data with

.

Date: Thu, 9 Sep 2004 01:00:35 0800

From: "=? GB2312? B? W87qobqi? =" <>

TO: "Dreamchild"

? Subject: = gb2312 B xOO6w2RyZWFtY2hpbGSjrMOww8G08sjE = X-mailer: Foxmail 5.0 [cn] Mime-Version: 1.0 Content-Type:??? Multipart / mixed; boundary = "===== 001_Dragon788446150325 _ =====" This is a multi-part message in MIME format - ===== 001_Dragon788446150325 _ ===== Content-Type: text / plain; charset = "gb2312" Content-Transfer-Encoding:. base64 1 / C tLXEZHJlYW1jaGlsZM / Iyfqjug0KoaGhodXiysfSu7fi08q8 / Q Gjdqo = - ===== 001_dragon788446150325 _ ===== CONTENT-TYPE: image / gif; Name = "mm.gif" Content-Transfer-Encoding: Base64 Content-Disposition: attachment; filename = "mm.gif" R0lGODlheAB4AIddABwNCixIjJtjkLO8iZux0NK2xpVJT9XayJWNuDA0Vt5Xh Sw7dLc7p6Fh3mD (side to be omitted on a tourbillon MM.gif Base64 encoded file content) w75UTdHFHwD / 1Ex6cBSs0jHpKaySFXI4XCwAEhPkRsUSBQQAOw == - ===== 001_Dragon788446150325 _ ===== content-Type: application / octet-stream; name = "= gb2312 B y7XD9y50eHQ = =????" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename = "= gb2312 B y7XD9y50eHQ = =????" 1eK49k1Nv8mwrrK7v8mwrqGjDQo = - ===== 001_Dragon788446150325_ = ==== -. 250 ok: Queued As 7cda613a26e quit 221 BYE This is the SMTP protocol, where the version of the RFC821 document see:

Http://itboy.cn/data/rfc821.doc

Because it is Chinese version, everyone spends some time, and it will not go to the principle. Only list status identity:

211 System status or system help response

214 Help Information

220

Service

221

Service Close Transport Channel

250 required mail operations

251 users are non-local, will forward

354 Start the mail input,

.

end

421

The service is not ready, turn off the transfer channel (when the answer can be turned off, this response can be used as a response to any command) 450 requires that the mail operation is not completed, the mailbox is unavailable (for example, mailbox busy) 451 to give up the requirements of the requirements; 452 System storage, required operations do not perform 500 format errors, commands are unrecognizable (this error also includes command line too long) 501 Parameter Format Error 502 Command Uncover 503 Error command sequence 504 Command parameter Do not implement 550 required mail operation Not completed, the mailbox is unavailable (for example, the mailbox is not found, or if it is not accessible) 551 users are non-local, please try 552 excess storage allocation, the required operation does not execute 553 mailbox name unavailable, the required operation is not executed, such as the mailbox format Error) 554 operation failed

It can be seen from this point that the user name and password of the SMTP server are different from the general via SMTP proxy.

Describe the entire process:

First, a mail switch of 263.NET is obtained by the aforementioned method, and then connected to this switch. Then connect to the 25 port of this server,

The server returns 220.

Then indicate the username, send an email (person), receive the mailbox (person). Receive the data written to the mail.

The data is divided into two parts: the body of the mail header and the message.

The email header contains: time, send mailbox (people), receive mailbox (people), theme, sender, MIME version number, email content type and split.

There are some strings encoded with Base64, which are the original Chinese characters. In fact, we can write directly to Chinese when making a SMTP proxy mail sending program.

This is the type and split of the email content, and others are easy to understand.

The type of mail content here is Multipart / Mixed; indicating that it is mixed by a variety of formats.

The separator is used to separate the content part of the message and each accessory. Use the Boundary keyword and key value to define.

For example, this example uses ===== 001_dragon788446150325 _ ===== to indicate that there is a detail problem in this side, the key value is best to use ", do not have spaces. For example, if you use boundary == ==== 001_dragon788446150325 _ =====,, the foxmail5.0 will not process the mail correctly, and the content part of the message is treated as the entire base64 garbled text, but I log in to the 263.net website to get the letter. Seeing the email is turned normally.

The content part of the message is separated by two minusks-re-connected separators.

The mail main body is from the first - ===== 001_dragon788446150325 _ ===== start, to the second - ===== 001_dragon788446150325 _ ===== is the first part of the content

Content-Type: Text / Plain;

Charset = "GB2312" Content-Transfer-Encoding: Base64

These two sentences explain the character sets and encodings of their types and content. Here is the Base64, then a blank line, plus "Dear Dreamchild: / r / n This is an email." This string's base64 encodes the body part of the message.

In fact, we can specify Content-Transfer-Encoding: 8bit and then you can use it in the body part.

Next, it is partially spaced apart parts.

There is a content-disposition: attachment; to illustrate this part is an attachment, as well as the related file name filename = "mm.gif".

The attachment content part is to read the file into a byte array, then turn the byte array into the Base64 encoded string. This is the content of MM.GIF.

The third part is an attachment 2 test .txt file, test .txt is also processed into base64 format by Foxmail, which can be represented by the original text.

After the last finished, use "Enter a Row. Return to the Rank" indicates the end of the DATA part.

If you send the server correctly, you will return a 250 state.

Then use the quit command with the server 3166

6. Analysis of Mail Send Program Programming

Let's define a mail structure to describe the individual properties of the message.

Public struct mailcontent // message content

{

Public string to; // recipient address

Public String Toname; // Recipient Name

Public string from; // sender address

Public string fromname; // send a name

Public String Title; // Theme

Public string body; // text content

Public Bool UseAttachment; // Whether to use attachments

Public String [] attachmentlist; // attachment list

} The value is obtained from each control, and the example is assigned to this structure. The value of the value includes determining whether the mailbox format is correct, we use a regular expression to determine. as follows:

Regex.ismatch (mailbox string, @ "@ ([/ w - /.] ) @ (/ [[0-9] {1, 3} /. [0-9] {1,3} /. [0-9] {1,3} /.) | ([/ W -] /.))) ([A-ZA-Z] {2, 4} | [0-9] {1, 3}) (/]?) $ ")

If the returned value is fake, use the error prompt to prompt. After the value is finished, create a work thread to send the message. The thread starts the list of mailbox domain parts through local DNS. The switch is then taken for the exclusator of its minimum priority to be used for future transmission. For example, the domain name of DreamChild@263.net This mailbox 263.NET has a priority value of 10 MX record mx12.263.net, then connects to the server to send commands and receive returns. Some of the following code is listed below:

About Creating a SOCK Socket:

TCPCLIENT SOCK = New TcpClient ();

NetWorkstream NetStream;

Sock.NodeLay = true; // Does not use the delay algorithm to speed up the transmission of the small data packet.

Sock.receivetimeout = 10000; // Receive timeout is 10 seconds.

Sock.Connect (Server, Port);

NetStream = Sock.getStream ();

The Nagle algorithm of the Socket will reduce the transmission speed of the small datagram, and the system defaults to use the Nagle algorithm. So set nodelay to turn off it to speed up the transmission of small data. About Send method:

Byte [] Sendarray = Encoding.default.getbytes (SendString); NetStream.write (Sendarray, 0, Sendarray.Length);

First turn the string to the byte array and send it to the Receive method:

Const int maxReceivesize = 1460;

....

Byte [] buffer = new byte [maxReceivesize];

Length = netstream.read (buffer, 0, maxreceivesize);

IF (Length == 0)

Return NULL;

....

ReceiveString = encoding.default.getstring (buffer, 0, length);

According to "In the Sock_Stream mode, if the single transmission data exceeds 1460, the system will be divided into multiple datagram, which will be a data stream in the other party, and the application needs to increase the determination of the broken frame. Of course, you can use a modified registry. The mode changes the size of 1460, but Micrcosoft believes that 1460 is the best efficiency parameter, not recommended to modify it. "This is set up to receive 1460 bytes, but in fact, the return code does not use so many bytes, this is what I used to write The received function written in the HTTP network program, retains this method. After receiving, turn it back to the string back.

Send = "Date: {$ time} / r / n"

"From: {$ fromname} <{$ from}> / r / n"

"To: {$ toname} <{$ to}> / r / n"

"Subject: {$ TITLE} / r / n"

"X-MAILER: NOSMTPSENDER [Cai Xiaohui Making] / R / N"

"MIME_VERSION: 1.0 / r / n"

"Content-Type: Multipart / Mixed; Boundary = /" {$ SPLITLINE} / "/ r / n"

"/ r / n" // The head ends, and the body is started.

"- {$ SPLITLINE} / r / n" // Content section.

"Content-Type: Text / Plain; Charset = GB2312 / R / N"

"Content-Transfer-Encoding: 8bit / R / N"

"/ r / n"

"{$ BODY} / R / N"

"/ r / n";

Attachment = "";

Attachment = "- {$ SPLITLINE} / R / N";

Attachment = "Content-Type: Application / OcTet-stream; Name = {$ FileName} / r / n";

Attachment = "Content-Disposition: attachment; filename = {$ filename} / r / n";

Attachment = "Content-Transfer-Encoding: Base64 / R / N";

Attachment = "/ r / n";

// Replace the first line to prevent the replacement of the accessory content.

Attachment = attachment.replace ("{$ Splitline}", splitline); attachment = attachment.replace ("{$ filename}", file.name);

Attachment = Convert.TOBASE64STRING (Filebytes, 0, Length);

Attachment = "/ r / n / r / n";

Send = attachment; presses the format in the format, then replaces the {$ Variable Name} in order, then the TIME variable name is:

DateTime.now.toString ("R"). Replace ("GMT", "China Standard Time")

I don't know if the VS2003 bug, with the "R" parameter output the current time RFC format Greenwich time, no localization time is automatically converted, such as China time 9 o'clock, it did not subtract 8 hours. Just add GMT directly after the current time. "So we will change" GMT "to" China Standard Time "to school. According to a question and answer," Communicate ", if there is a wrong , Save the wrong information, then return false; if the entire send process is not wrong:

NetStream.close ();

Sock.close ();

end. Interface screenshot of the program:

Seven, the last words

Thank you very much, I am very patiently finished. I spent four all night (actually sleeping in the morning) time to write software and tutorial's hard work. This software is a better finished product after learning for half a month. I started learning truly programming from the big two, using the nine months VB and wrote the C / MFC program for another year. Now studying C #. It feels that the foundation of C is very easy.

The sending method of the mail attachment of this document refers to the C source code of the Senior (http://www.luocong.com), otherwise it may be repeated to think about it. Thanks to Teacher Luo's selflessness.

After writing this stuff, after four days, my summer vacation is over, the next semester is a big four. A very fascinating school year, I want to find a good job in Shanghai after graduation. I want to invite my seniors in the industry to guide me, do you have to cross the threshold of Shanghai University software? I will be more effort in this year.

You can disseminate this software, source, and related documents arbitrarily, but keep integrity.

If it is used for commercial purposes, I need to agree.

my contact information:

Address: Zhangzhou Teachers College 082 Mailbox (363000)

Name: Cai Xiaomei

e-mail:

QQ: 22415

I hope we can make a friend.

If you need me to answer within a year, please send an inquiry to the [Information Technology] section on http://bbs.zzsy.com.

I will help you with your efforts and capabilities.

Programmed by Cai Xiaomei

2004.9.7 - 2004.9.9

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

New Post(0)