Class for ASP to send mail

Source: Internet
Author: User
Tags execution file upload mail rar table name zip
Send mail

I. Procedural thinking

All programs, the main implementation of two functions, one, send mail, two, upload attachments. Use the No component upload program to upload attachments to the server, after sending, will delete the message on the server. To implement these two functions, a database is required to hold the message content and attachment information (filename). There are two situations in which a message is sent: one is a message without an attachment, and the other is a message with an attachment.

1. Send a message without attachments. Users according to the actual situation to fill in the recipient, sender, CC, Secret Send, SMTP server address, mail subject, mail content and other information, such information, the recipient, sender, message subject, the content of the message must be filled out, otherwise will not receive mail. If the SMTP server supports SMTP authentication, then you fill in the username and password of the post office. For example, you fill in the sender address is xxxx@163.com, because 163 of the SMTP service, support SMTP authentication, so you need to have your username in 163 xxxx, password * * * *, so as to smoothly send mail; Your sender address is xxxx@hotmail.com, because Hotmail does not require SMTP authentication, so you do not need to fill in the username and password. Just remember that your outgoing SMTP server supports SMTP authentication, and you need to fill in the username and password. After you fill out the form, click the "Send" button to send the message directly. This process was done in mail.asp and inc_clsemail.asp.

2. Send a message with an attachment. This process, mainly in three steps, one, fill out the form information (IBID.), but before the "Send" button, you need to go to the second step, send the attachment. Second, this step is mainly to upload attachments to the server. Need the server to support FSO, Dictionary, stream and other components. Before entering the upload attachment, create a record in the database, just fill out the form information existing table, and then select local need for local RAR or zip file, choose the point "Upload" button on the line, after the program will update the database in the attachment file name and field content and automatically jump to the letter page, The sending page reads the message from the database and displays it, sending the attachment at the point "send". This process is mainly done by mail.asp, inc_clsemail.asp, inc_clsupload.asp, upload.asp and uploadok.asp.

A list of files used in this sender's program:
Attachment.mdb ' Message information temporary repository
Install.asp ' Create a temporary table of message information in a database
Mail.asp ' Send mail
Upload.asp ' File Upload
Uploadok.asp ' file uploaded successfully
Inc_clsemail.asp ' Mail Send class
Inc_clsupload.asp ' no component upload class
inc_set.asp ' Some table color settings

Two. Establishing a database
1. Open your access to create a file name: Attachment.mdb. Add the following fields:
(1). ID type is autonumber (ID number that holds message information)
(2). Smtpcheck type is a Yes/No field (storage requires SMTP authentication)
(3). From type is a text field (store sender's email address)
(4). FromName type is a text field (store sender's name)
(5). To type as a text field (store the email address of the addressee)
(6). BCC type is a text field (store the email address of the secret sender)
(7). CC Type is a text field (the email address of the CC person)
(8). Server type is a text field (host SMTP server address)
(9). Subject type is a text field (store message subject)
(a). The body type is a Memo field (the contents of the message)
(one). Username type is a text field (store mailbox login username)
(in). Password type is a text field (the password that holds the mailbox login)
The filenames type is a text field (the file name that holds the attachment).
Note: You can set the field to allow null.

Of course, you can add the field you think you need, if you change the field name or table name to another name, you should make the appropriate changes to the program, or you will be wrong. If you do not want to manually build the table and add fields, then you can run the install.asp file in the browser, it can automatically build the table, you can be lazy:

2. Before you start writing, you can list the SQL statements you want to use.

' Search for mail messages with ID number 1 in the database
SQL = "SELECT * from Attachment ORDER by WHERE id=1"
' This statement is used when adding new temporary mail information.
Sql= INSERT into Attachment (Smtpcheck,from,fromname,to,bcc,cc,server,subject,body,username,
Password,filenames) VALUES (True, ' cjj8110@hotmail.com ', cjj ', ' cjj8110@hotmail.com ', ', ', ', ', ', ', ', ' Test ', ' test mail-sending program ', ' Cjj8110 ', ' ******** ', ' 1,zip,1.rar ')
' Deletes all the data in the table.
SQL = "DELETE from Attachment"
' Deletes the record of the specified ID in the table
SQL = "DELETE from attachment WHERE id =" & ID
' Update table, the contents of the filenames field for the specified ID
SQL = "UPDATE attachemnt SET filenames= '" & Filenames & "WHERE id=" & ID


Three. Write code
Install.asp: I wrote this file, considering it was a bit of a hassle to hand-build the table. Files are used primarily with CREATE TABLE and drop TABLE statements, but some databases may not support this statement because of database reasons. This article takes access as an example, because Access supports these two statements, if the novice still does not understand that it does not matter, think there is a chance to study well:). Because it is not clear that the database defines those keywords, the table and field names are surrounded by [] when you create tables and fields, even if the table name or field name conflicts with the keywords in the database, it does not cause a program error. However, before running this program, you must first create a database name in Access that is Attachment.mdb, and you can create it without creating a table for it.

Install.asp's source code:
<% ' This file is best deleted after execution, because if you do not pay attention to the execution of the database, you will lose all the data, remember! Dim Sys_strtablename,sys_strsql,sys_objrs ' The name of the table to be created sys_strtablename = ' attachment ' Set objconn = Server.createobje CT ("ADODB"). Connection ") ' OLE DB way to open a database Connection object connection string strcon=" Provider=Microsoft.Jet.OLEDB.4.0;Data source= "& Server.MapPath ("Attachment.mdb") objConn.Open Strcon ' and the database have been established to operate on it. ' DROP table is an SQL statement that deletes a table from the database. Some databases may not be supported. Sys_strsql = "DROP table [" & Sys_strtablename & "]" "' when there is an error, the jump executes the following statement ' because if a table that does not exist in a database in the drop table causes a program error , ' so added this statement on Error Resume nex<p> This news total <font color=red><b>14</font></b> page previous <a href=1 95044.html>1</a> <a href=195044-2.html>2</a> <a href=195044-3.html>3</a> <a href =195044-4.html>4</a> <a href=195044-5.html>5</a> <a href=195044-6.html>6</a> <a href=195044-7.html>7</a> <a href=195044-8.html>8</a> <a href=195044-9.html>9</a> <a href=195044-10.html>10</a> <a href=195044-11.html>11</a> <a gt;12</a> <a href=195044-13.html>13</a> <a href=195044-14.html>14</a> next page </td>& Lt;/tr></tbody></table></div><table Class=pagespacenewsseparator cellSpacing=0 Cellpadding=1 width= "100%" border=0><tbody><tr><td width= "71%" Height=24><a href=/ sendmail.asp?filename=195044 Target=_blank class=a01> recommended friends </a> <span class=pageicon>| <a href=/member/add_favorite.asp?filename=195044 Target=_blank class=a01> Channel Collection </a> | <a class=a01 onclick=javascript:doprint () href= "" > Print Documents </A> | <a href=/senderror.asp?f</p>



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.