Simple and quick implementation ASP online email function
When writing an online application, you often encounter problems that need to be sent online. The message is determined by the program. If you use the ASP mode to write online applications, how simple, quickly achieve this function? The author uses the ASP COM component function in practice, implements a small component that emails in VB, which can be implemented in the ASP only by easy calls. All mail processing mechanisms are encapsulated in this component, which is very convenient to use. The basic development principle of this component will be described in detail below and the application in ASP.
1. With the WINSOCK control and the SMTP contact and SMTP connections including the SMTP, the main procedures are as follows: Create a FRMSENDMAIL form, which contains a Winsock control, with a few public variables: Public MSTMP AS STRING / / STMP PUBLIC MFROM AS STRING / / FROM address PUBLIC MSUBJECT AS STRING // Mail Topic PUBLIC MTEXT AS STRING // Mail Text Sock.Connect MSTMP, 25 // and Send after stmp mail to establish contact private sub sock_connect () sflag = sfconn // connection is successful set the parameters end sub private sub sock_dataarrival (byval bytestotal as long) on error goto daerr dim s as string sock.getdata s select case sflag case sfstart case sfconn Sflag = sfhelo // Handshake information Hello Send "Helo" && mmyname case sflag = sffrom send "mail from:" && getreal (mfrom) Case SFFROM IF LEFT (S, 3) <> "250" THEN GOTO SRVERR /// If you successfully send a message SFLAG = SFRCPT Send "RCPT TO:" && GetReal (MTO) Case SFRCPT IF LEFT (S, 3) <> "250" THEN GOTO SRVERR // If successfully starts sending data sflag = sfData send "DATA "Case SfData if Left (s, 3) <>" 354 "THEN GOTO SRVERR SFLAG = sfsendover // The data includes 4 items, finally. End Send" from: "&& mfrom send "To:" && mto send "Subject:" && msubject && vbcrlf send mtext send "." Case Sfsendover if Left (s, 3) <> "250" Then Goto srver sflag = sfstart sendok = true send "quit" End SELECT EXIT SUB END SUB 2. The above function is packaged in a class in a class that cannot be present in the components that the ASP can use, so the above form is encapsulated by class modules. First, create a form at the beginning of the class: private sub class_initialize () set frm = new frmsendmail End Sub Packed the public variable of the form as the attribute package in the class module. The function interface of the form is: Public SUB Send () frm.sendstart end Sub 3. Registering this component to compile the above engineering into a DLL file, can be registered with VB or manual registration.