Task requirement: a conference contribution system automatically sends a confirmation email to the author when the author submits the paper abstract.
(Note: The submission system uses myreview.
)
You can perform this task in the following ways:
- Configure the sendmail service on the server and use the mail function in PHP to send emails;
- Install mutt + msmtp on the server, or install other SMTP client programs on the server, and send emails using the SMTP client program.
- Write a C/S program. When an author submits a thesis, the client program on the server combines the mail content and notifies the server program listened to on my computer, the server program then calls the mail sending script on my computer to send the mail. This c/s program can be written in Java, C, PHP, etc.
- Use NC or telnet to send emails using raw SMTP protocol
I have never liked Sendmail since I used Linux. I also don't want to install additional software on the server, so method 2 gives up. In comparison, Method 4 is simpler than method 3.
Method 4: Use tcpdump to intercept a complete SMTP sending process, and then write a program to simulate this process.
Start tcpdump to monitor incoming and outgoing packets:
[Root @ jcwkyl review] # tcpdump-vvv-T-X-s 1500-w Data host mail.jlu.edu.cn
-Vvv indicates that captured data packets are recorded in the most detailed format.-T indicates that no time stamp is recorded, and-X indicates that hex and ASCII are used to display the data packet content, -s indicates that the display length is 1500 instead of the default 68, and-W indicates that the display is output to the data file.
At the same time, send an email.
[WHB @ jcwkyl bash] $ echo "Mail content" | mutt-s "test subject" jcwkyl@gmail.com
Here tcpdump:
[Root @ jcwkyl review] # tcpdump-vvv-T-X-s 1500-w Data host mail.jlu.edu.cn
Tcpdump: listening on eth0, link-type en10mb (Ethernet), capture size 1500 bytes
Got 34
34 packets are captured. View record files:
[Root @ jcwkyl review] # tcpdump-vvv-t-X-s 1500-r data | less
There are a lot of outputs. You can see the format of the data exchange. Take the following three data packets as an example:
<! --
@ Page {size: 8.5in 11in; margin: 0.79in}
P {margin-bottom: 0.08in}
-->
IP (tos 0x0, ttl
61, id 51365, offset 0, flags [DF], proto: TCP (6), length: 63)
Mail.jlu.edu.cn. sm
Tp> jcwkyl. gridlab.57415: P, cksum 0x9765
(Correct), (11) ack 1 win 1448 <nop, nop, timestamp 203
2907544
165074058>
0x0000:
4500 003f c8a5 4000 3d06 577f cac6 1038
E ..?.. @. =. W... 8
0x0010: 0a3c 385a 0019 e047 c0c6 7dbd eeb9 52bd
. <8Z... G...}... R.
0x0020: 8018 05a8 9765 0000 0101 080a 792b b518
... E... y + ..
0x0030: 09d6 d48a 3232 3020 4553 4d54 500d 0a
... 220. ESMTP ..
IP (tos 0x0, ttl 64, id 34360, offset 0,
Flags [DF], proto: TCP (6), length: 52) jcwkyl. gridlab.574
15>
Mail.jlu.edu.cn. smtp:., cksum 0 xebee (correct), 1:1 (0) ack 12 win 46
<Nop, nop, timestamp 165074
058 2032907544 & gt;
0x0000: 4500 0034 8638 4000 4006 96f7 0a3c 385a
E. 4.8 @. @... <8Z
0x0010: cac6 1038 e047 0019 eeb9 52bd c0c6 7dc8
... 8. G... r ...}.
0x0020: 8010 002e ebee 0000 0101 080a 09d6 d48a
................
0x0030: 792b b518
Y + ..
IP (TOS 0x0, TTL 64, Id 34361, offset 0, flags [DF],
PROTO: TCP (6), length: 68) jcwkyl. gridlab.574
15>
Mail.jlu.edu.cn. SMTP: P, cksum 0x1dcb (incorrect (-> 0x8015 ),
(16) ack 12 win 46 <NOP, NOP, T
Imetstamp 165074058
2032907544>
0x0000:
4500 0044 8639 4000 4006 96e6 0a3c 385a
E.. D.9 @. @... <8z
0x0010: cac6 1038 e047 0019 eeb9 52bd c0c6 7dc8
... 8. G... r ...}.
0x0020: 8018 002e 1dcb 0000 0101 080a 09d6 d48a
................
0x0030: 792b b518 4548 4c4f 206c 6f63 616c 686f
Y + .. Ehlo. localho
0x0040: 7374 0d0a
St ..
The first packet is sent to me by the server. The content is 220 ESMTP. The second packet has no content to worry about. The third packet is also sent to the server. The data content is: EHLO/x20localhost/x0d/x0a
In this way, find the 34 data packets and extract all the data content sent from me to the email server. The final result is as follows:
EHLO localhost/r/n
Auth login/r/n
<Para1>
<Para2>
Mail from: <whb@jlu.edu.cn>/r/n
Rcpt to: <jcwkyl@gmail.com>/r/n
DATA/r/n
Date: Fri, 1 5 Jan 2010: 06 + 0800/r/n
From: E-mail Address <addr@jlu.edu.cn>/r/n
To: jcwkyl@gmail.com/r/n
Subject: test subject/r/n
Message-ID: <20100115091 006 GA12962@jcwkyl.gridlab>/r/n
Mime-Version: 1.0/r/n
Content-Type: text/plain; charset = us-ascii/r/n
Content-Disposition: inline/r/n
User-Agent: Mutt/1.4.2.2i/r/n
Mail content/r/n/x2e/r/n
QUIT/r/n
The above is the entire process. Note that there are two/R/n before the email body starts. The email body ends with/R/n/x2e/R/n. /R is the hexadecimal/x0d, And/N is the hexadecimal/x0a.
The preceding <para1> and <para2> are two strings, which are used for identity authentication by context prediction. <para1> and <para2> are used here.
The next step is to write a program to simulate this process. Because the conference contribution system uses PHP to write a program to simulate the mail sending process, the final code is as follows:
// Encapsulate the mail function <br/> function SendMail ($ to, $ subject, $ mail, <br/> $ from = "", $ replyTo = "", $ cc = "") <br/>{< br/> // Construct the header <br/> $ header = ""; <br/> if (! Empty ($ from) $ header. = "From: $ from/r/n"; <br/> if (! Empty ($ cc) $ header. = "Cc: $ cc/r/n"; <br/> if (! Empty ($ cc) $ header. = "Reply-to: $ replyTo/r/n"; <br/> // Add the signature file <br/>/* if (file_exists ("Signature ")) <br/>{< br/> $ mail. = readfile ("Signature "); <br/>}< br/> */<br/> // Use the standard mail function <br/> // Sometimes the-f option does not work <br/> // mail ($, $ subject, $ mail, $ header, "-f $ from"); <br/> // mail ($ to, $ subject, $ mail, $ header ); <br/> $ protocol_data = arr Ay (<br/> 'EHLO' => 'ehlo localhost', <br/> 'auth' => 'auth login ', <br/> 'para1' => '<PARA1>', // replace it with your own identity authentication string <br/> 'para2 '=>' <PARA2> ', <br/> 'mailfrom' => 'mail FROM: <addr@jlu.edu.cn> ', <br/> 'rcp' => 'RCPT TO: <'. $. '>', <br/> 'data' => 'data' <br/>); <br/> $ mailcontent = "From: from Address <addr@jlu.edu.cn>/r/n "; <br/> $ mailcontent. = 'to :'. $. "/r/n"; <br/> $ mailcontent. = 'subjec T :'. $ subject. "/r/n"; <br/> $ mailcontent. = $ mail. "/r/n/x2e/r/n"; <br/> $ mailcontent. = "QUIT/r/n"; <br/> $ handler = popen ("/usr/bin/nc mail.jlu.edu.cn 25", "w "); <br/> if (! $ Handler) {<br/> echo '<mce: script type = "text/javascript"> <! -- <Br/> alert ("error"); <br/> // --> </mce: script> '; <br/>}< br/> foreach ($ protocol_data as $ value) {<br/> fwrite ($ handler, $ value. "/r/n"); <br/>}< br/> fwrite ($ handler, $ mailcontent. "/r/n"); <br/> pclose ($ handler); <br/>}< br/>
The comment-out mail function is the previous Code of the submission system, and the mail function is the code used to simulate the mail sending process. The same functions can be easily implemented in other languages.