How to use ASP & Export/Convert to CSV and send email attachment This is learn/tutorial asp developers how to using asp Export/Convert to CSV and send email attachment
ShotDev Focus:
- ASP & Export/Convert to CSV and send email attachment
Example
asp_csv_mail.asp
<%Option Explicit%> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <% Dim objFSO,oFiles Dim Conn,strSQL,objRec Dim sFileName '*** Connect to Access ***' Set Conn = Server.Createobject("ADODB.Connection") Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("shotdev/mydatabase.mdb"),"" , "" strSQL = "SELECT * FROM customer " Set objRec = Server.CreateObject("ADODB.Recordset") objRec.Open strSQL, Conn, 1,3 If Not objRec.EOF Then sFileName = "shotdev/customer.csv" '*** Create Object ***' Set objFSO = CreateObject("Scripting.FileSystemObject") '*** Create Text Files ***' Set oFiles = objFSO.CreateTextFile(Server.MapPath(sFileName), 2) While Not objRec.EOF oFiles.WriteLine(objRec.Fields("CustomerID").Value&","&_ objRec.Fields("Name").Value&","&_ objRec.Fields("Email").Value&","&objRec.Fields("CountryCode").Value&","&_ objRec.Fields("Budget").Value&","&objRec.Fields("Used").Value) objRec.MoveNext() Wend oFiles.Close() Set oFiles = Nothing Set objFSO = Nothing '**************** Send Email ******************' Dim myMail,HTML,strMsg Set myMail = Server.CreateObject("CDONTS.NewMail") If Trim(sFileName) <> "" Then myMail.AttachFile Server.MapPath(sFileName) End If myMail.From = "Webmaster <webmaster@shotdev.com>" myMail.Value("Reply-To") = "shotdev@hotmail.com" myMail.To = "member@shotdev.com" myMail.Subject = "My CSV" myMail.MailFormat = 0 myMail.BodyFormat = 0 myMail.Body = "Convert Access to CSV" myMail.Send Set myMail = Nothing '*************** End Send Email ***************' Response.write "Generate CSV and Email Sending." End If objRec.Close() Conn.Close() Set objRec = Nothing Set Conn = Nothing %> </body> </html>
Create a asp file and save to path root-path/myasp/