Classic ASP application - Need help in sending an auto email from application with excel as attachment

gracesoft used Ask the Experts™
Hello Experts,
                         You are doing a great Job.

In our  hotel management software application classic asp, we are generating a report and we would want to send the generated report in excel format as attachment.  We already have the auto email feature working fine. We need your assistance in sending the report as an attachment. We dont want to send an URL in the email and retrieve the excel sheet from the server.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dan McFaddenSystems Engineer

What are you using to do the email send?  CDO, CDOSYS, a 3rd party object?

If its CDO, here is a MS Blog article describing the code required.


oatesjohnrSoftware Engineer 2

I'm guessing you're using CDO in which case you would want to use the .AddAttachment method. See below from:

Sending a text email with an attached file.
By repeating the .AddAttachment method you can attach more than one file.
When attaching files keep in mind that your recipient may be limited in their
ability to receive files above a certain size. Many ISPs limit emails to 8 or 10MB each.
You should not send large files to anyone before obtaining their permission.

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = ""
objMessage.To = ""
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"


Thanks.  Now, when we generate the report, the excel gets downloaded in the same page. We would want the code in classic ASP to save this excel in a path in server and then we could retrieve that and send as an attachment with the emai.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Dan McFaddenSystems Engineer

OK, this process what not mentioned in your original post.

You will have to update your report generating code to save the file somewhere on the server.  Then pass the the location of the newly generated file into a function or sub-routine that sends the email with attachment.



I have given the code used. We want the code/assistance on  how to save the file in a path in the server.

SetHeaders strReportName & ".xls", "Application/vnd.excel"
Response.Write "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">"
Response.Write "<head>"
Response.Write "<!--[if gte mso 9]><xml>"
Response.Write "<x:ExcelWorkbook>"
Response.Write "<x:ExcelWorksheets>"
Response.Write "<x:ExcelWorksheet>"
Response.Write "<x:Name>"& strTable &" Report</x:Name>"
Response.Write "<x:WorksheetOptions>"
Response.Write "<x:Print>"
Response.Write "<x:ValidPrinterInfo/>"
Response.Write "</x:Print>"
Response.Write "</x:WorksheetOptions>"
Response.Write "</x:ExcelWorksheet>"
Response.Write "</x:ExcelWorksheets>"
Response.Write "</x:ExcelWorkbook>"
Response.Write "</xml>"
Response.Write "<![endif]--> "
Response.Write "</head>"
Response.Write "<body>"
'Response.Write "<table><tr><td><font color='#0000FF' size='2'><b> Availability Calendar<b></font></td></tr></table>"

Response.Write "</body>"
Response.Write "</html>"
Dan McFaddenSystems Engineer

Instead of using your Response.Write method, you should create a FileSystemObject (FSO) and write each line to a File object.


		Const cdoSendUsingMethod        = ""
		Const cdoSendUsingPort          = 2
		Const cdoSMTPServer             = ""
		Const cdoSMTPServerPort         = ""
		Const cdoSMTPConnectionTimeout  = ""
		Const cdoSMTPAuthenticate       = ""
		Const cdoBasic                  = 1
		Const cdoSendUserName           = ""
		Const cdoSendPassword           = ""
		Dim objConfig  ' As CDO.Configuration
		Dim objMessage ' As CDO.Message
		Dim Fields     ' As ADODB.Fields
		Set objConfig = Server.CreateObject("CDO.Configuration")
		Set Fields = objConfig.Fields
		With Fields
		   .Item(cdoSendUsingMethod)       = cdoSendUsingPort
		   .Item(cdoSMTPServer)            = your smtp server
		   .Item(cdoSMTPServerPort)        = 25
		   .Item(cdoSMTPConnectionTimeout) = 20
		   .Item(cdoSMTPAuthenticate)      = cdoBasic
		   .Item(cdoSendUserName)          = your send email adress
		   .Item(cdoSendPassword)          = your password
		End With
		Set objMessage = Server.CreateObject("CDO.Message")
		Set objMessage.Configuration = objConfig
		With objMessage
		   .To       =  email receipent
		   .From     = email sender
		   .Subject  = subject of mail
		   .HTMLBody = your email
		End With
		objMessage.AddAttachment /path of your file
		Set Fields = Nothing
		Set objMessage = Nothing
		Set objConfig = Nothing

Open in new window


Thanks. We will try this .
And this works or not ?
    We did a windows application for this as an exe and called it in classic asp and now it works.


We had to find the solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial