Link to home
Create AccountLog in
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.
Avatar of Dan McFadden
Dan McFadden
Flag of United States of America image

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
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
Avatar of gracesoft
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.
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
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>"
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
		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

Thanks. We will try this .
And this works or not ?
ASKER CERTIFIED SOLUTION
Avatar of gracesoft
gracesoft

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
We had to find the solution.