Implement ASP file to send Mail Online

Source: Internet
Author: User
Tags goto implement mail variables all mail
In practice, the author uses ASP's COM component function to implement a small component in VB, which can be realized only by easy invocation in ASP. All mail processing mechanisms are encapsulated in this component and are extremely handy to use. The basic development principle of the component and its application in ASP are described in detail below.

1. Use the Winsock control to contact SMTP for outgoing messages

The connection to SMTP includes the whole process of shaking hands, sending data, and shutting down, the main procedures are as follows:

Create a Frmsendmail form that contains a Winsock control with the following public variables:

Public mstmp as String

Stmp to send mail

Public Mfrom as String

From address

Public MTo as String

Arrival Address

Public Msubject as String

Message subject

Public Mtext as String

Message body

Sock.connect Mstmp, 25

Establish contact with the stmp that sent the message

Private Sub Sock_connect ()

Sflag = Sfconn

Set parameters after successful connection

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

Send a handshake message hello

Send "HELO" && mmyname

Case Sfhelo

Sflag = Sffrom

Send "MAIL from:" && getreal (Mfrom)

Case Sffrom

If left (S, 3) 〈〉 "Then" GoTo Srverr

If the receive mail address is sent successfully

Sflag = Sfrcpt

Send "RCPT to:" && getreal (MTo)

Case SFRCPT

If left (S, 3) 〈〉 "Then" GoTo Srverr

If you start sending data successfully

Sflag = Sfdata

Send "Data"

Case Sfdata

If left (S, 3) 〈〉 "354" Then GoTo Srverr

Sflag = sfsendover//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) 〈〉 "Then" GoTo Srverr

Sflag = Sfstart

Sendok = True

Send "Quit"

End Select

Exit Sub

End Sub

2. Encapsulate the above functionality in a class

Because the controls cannot exist in the components that the ASP can use, the above form is encapsulated by a class module. First create a form when the class is initialized:

Private Sub Class_Initialize ()

Set frm = New frmsendmail

End Sub

Encapsulates a form's public variable as a property in a class module.

The function interface for the form is:

Public Sub Send ()

frm. Sendstart

End Sub

3. Registering the component

Compile the above project into a DLL file, either through VB Registration or manual registration.

4. The application in ASP

The method is invoked as follows:

Set smail=server.createobject ("Sendmailx.mail")

smail.stmp= "166.166.1.1"

Smail.logfile= "E:\Logs\mail.log"

Smail.mfrom = Mfromname && "&& mfromaddr &&" "

Smail.mto = Mtoname && "&& mtoaddr &&" "

Smail.msubject = Msubject

Smail.mtext = Mtext

Smail.send

Where variables can be assigned or from the previous request page.

Due to the limitations of the layout, can not be described in detail, the need for this component of the friend to http://flyfly.533.net software programming column download.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.