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

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.

Regards,
Gracesoft.
gracesoftAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
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.

Link:  http://blogs.technet.com/b/heyscriptingguy/archive/2004/11/29/how-can-i-attach-a-file-to-an-email-sent-using-cdo.aspx

Dan
oatesjohnrSoftware Engineer 2Commented:
I'm guessing you're using CDO in which case you would want to use the .AddAttachment method. See below from: http://www.paulsadowski.com/wsh/cdo.htm


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 = "me@my.com"
objMessage.To = "test@paulsadowski.com"
objMessage.TextBody = "This is some sample message text."
objMessage.AddAttachment "c:\temp\readme.txt"
objMessage.Send
gracesoftAuthor Commented:
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.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Dan McFaddenSystems EngineerCommented:
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.

Dan
gracesoftAuthor Commented:
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>"

PrintTable"<td>","</td>","<tr>","</tr>","<table>","</table>"
Response.Write "</body>"
Response.Write "</html>"
Dan McFaddenSystems EngineerCommented:
Instead of using your Response.Write method, you should create a FileSystemObject (FSO) and write each line to a File object.

Links:
- http://www.w3schools.com/asp/asp_ref_filesystem.asp
- http://www.crydust.be/blog/2009/03/02/generate-excel-files-in-asp-classic/

Dan
Manuel Marienne-DuchêneITMCommented:
		Const cdoSendUsingMethod        = "http://schemas.microsoft.com/cdo/configuration/sendusing"
		Const cdoSendUsingPort          = 2
		Const cdoSMTPServer             = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
		Const cdoSMTPServerPort         = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
		Const cdoSMTPConnectionTimeout  = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
		Const cdoSMTPAuthenticate       = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
		Const cdoBasic                  = 1
		Const cdoSendUserName           = "http://schemas.microsoft.com/cdo/configuration/sendusername"
		Const cdoSendPassword           = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
		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
		   .Update
		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
		objMessage.send
		Set Fields = Nothing
		Set objMessage = Nothing
		Set objConfig = Nothing
	

Open in new window

gracesoftAuthor Commented:
Thanks. We will try this .
Manuel Marienne-DuchêneITMCommented:
And this works or not ?
gracesoftAuthor Commented:
Hi,
    We did a windows application for this as an exe and called it in classic asp and now it works.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gracesoftAuthor Commented:
We had to find the solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.