Summary of common function code in ASP.NET (1) - Send Mail

xiaoxiao2021-03-17  212

One. Implement mail system with ASP.NET

1

/ ** /

///

2 /// function: Implement Email 3 /// in the web page

4

Private

Void

Sendmail ()

5

{6 MailMessage M = New MailMessage (); 7 8 / ** //// sender address 9 m.From = tbfrom.text; 1011 / ** //// Recipient address 12 m.to = TBTO .Text; 1314 / ** //// Mail Topic 15 m.subject = tbsubject.text; 1617 / ** //// Mail content 18 m.body = tbovy.text; 1920 / ** /// Priority Level 21 Switch (DDLP.Selected Index) 22 {23 case 0:24 m.priority = mailpriority.high; 25 break; 26 case 1:27 m.priority = mailpriority.low; 28 break; 29 default: 30 m.priority = MailPriority.Normal; 31 Break; 32} 3334 / ** //// Set Mail Format 35 if (DDLP.Selected Index == 0) 36 m.bodyformat = mailformat.text; 37 else38 m.bodyformat = mailformat.html; 3940 / ** //// Set the server 41 if (TBSERVER.TEXT! = "") 42 {43 SMTPMAIL.SMTPSERVER = TBSERVER.TEXT; 44} 4546 / ** /////////ww string strfilename = fileselect.postedfile.fileName; 48 if (strfilename! = "") 49 m.attachments.add (New MaiLattachment) StrfileName)); 5051 / ** //// Send Mail 52 SMTPMAIL.SEND (M); 53}

two. Use Socket to receive mail

1

/ ** /

///

2 /// Receive mail 3 ///

4

Private

Void

SocketPopmail ()

5

{6 POP3 POP = New POP3 (TBServer.Text, Tbuser.Text, Tbpass.text); 7 int n = pop.getNumberofnewMessages (); 8 if (n == - 1) 9 {10 Response.write ("