Advertisement

05.09.2008 at 12:08PM PDT, ID: 23390532
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.9

Specify Content-Type for Attachment to CDO.Message in ASP Program

Asked by rkelso in Active Server Pages (ASP), Microsoft Excel Spreadsheet Software

Tags:

I have an ASP program that is sending an email with an Excel spreadsheet as an attachment.  The Excel spreadsheet attachment is actually just a dynamically-created html table (which Excel can interpret).

The email sends fine and the attachment (abcde.xls) works fine.  When opening the attachment however, Excel complains that the file is in a different format than that specified by the file extension.  The user than has the opportunity to click "Yes" and the file opens fine in Excel, but I'd rather not have the user experience that "warning" message if I can aviod it.

I'm assuming anyway that the lack of a proper content-type specification is the problem.  I'm trying to find a way to specifiy the content-type of the dynamically created html table so that Excel recognizes the attachment as being valid Excel.  So, I put this line as the first line in the attachment:

     Content-Type: application/vnd.ms-excel;

When I do this, the line above ends up being placed in the first cell of the attached spreadsheet.  Not exactly what I was after.  So the question is, how can I get that content-type recognized as a content type and not just the first line of the attachment "body"?

I've attached one of my Excel attachments from email and also a code snippet that I'm using to send the email with the attachment.

Thanks all!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
Sub SendEmailWithAttachment(localFrom,localTo,subject,htmlContent,attachFile)
	Dim objSendMail,cdoConfig
	sch = "http://schemas.microsoft.com/cdo/configuration/"
	Set cdoConfig = Server.CreateObject("CDO.Configuration")
	cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
	cdoSendUsingPort = 2
	cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
	cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
	cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
	cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
	cdoBasic = 1
	cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
	cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
 
	cdoConfig.Fields.Item(cdoSMTPServer) = "192.168.1.211"
 
	With cdoConfig.Fields
		.Item(cdoSendUsingMethod) = cdoSendUsingPort
		.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
		.Item(cdoSMTPServer) = "192.168.1.211"
		.Item(cdoSMTPServerPort) = 25
		.Item(cdoSMTPAuthenticate) = cdoBasic
		.Item(cdoSendUserName) = "xxxx"
		.Item(cdoSendPassword) = "xxxx"
		.Update
	End With
 
	Set objSendMail = Server.CreateObject("CDO.Message")
	With objSendMail
		Set .Configuration = cdoConfig
		.From = localFrom
		.Subject = subject
		.HTMLBody = htmlContent
	End With
	objSendMail.To = localTo
	objSendMail.AddAttachment(attachFile)
	objSendMail.Send
	Set objSendMail = Nothing
	Set cdoConfig = Nothing
End Sub
Attachments:
 
Excel spreadsheet from email attachment with incorrect content-type specification
 
[+][-]05.09.2008 at 12:27PM PDT, ID: 21535771

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 12:34PM PDT, ID: 21535808

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 12:39PM PDT, ID: 21535857

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.09.2008 at 12:50PM PDT, ID: 21535926

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), Microsoft Excel Spreadsheet Software
Tags: ASP
Sign Up Now!
Solution Provided By: ruscomp
Participating Experts: 1
Solution Grade: B
 
 
[+][-]05.09.2008 at 12:58PM PDT, ID: 21535988

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628