Avatar of gracesoft
gracesoft
 asked on

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.
ASPWeb DevelopmentEmail Servers

Avatar of undefined
Last Comment
gracesoft

8/22/2022 - Mon
Dan McFadden

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
oatesjohnr

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
gracesoft

ASKER
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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Dan McFadden

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
gracesoft

ASKER
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 McFadden

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Manuel Marienne-Duchêne

		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

gracesoft

ASKER
Thanks. We will try this .
Manuel Marienne-Duchêne

And this works or not ?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
gracesoft

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
gracesoft

ASKER
We had to find the solution.