Link to home
Start Free TrialLog in
Avatar of kwk
kwk

asked on

CDONTS Attaching binary files

I am trying to attach a XLS file  to my emails.
When the receiver opens the mails, the attachments is not really valid. Any Suggestions ?

Code:
Dim Mail    
Set Mail = server.createobject("CDONTS.NewMail")

Mail.To = "kim@MrX.com"
Mail.Subject = "Reports from MR X"
Mail.Body = "Attached the 2 reports from MR X"  
Mail.AttachFile "C:\Book1.xls"
Mail.From = "kim@MrX.com"
Mail.Send
set mail = Nothing
Avatar of RickHalle
RickHalle

I doubt you will find a solution for this.
 http://support.microsoft.com/support/kb/articles/Q262/6/34.ASP

I think most email clients will refuse it because it can present a security risk. You may be able to send it as a plain text file but the receiver will need to change the extension if you do.

Rick Halle
It is easy to attach files to mail messages using the AttachFile method of the NewMail object. So if we wanted to attach a bitmap to the mail message we could do so like this:

objMail.AttachFile ("c:\images\logo.bmp", "Our logo")
This would attach the file logo.bmp with the caption "Our logo". By default, the attachment is encoded using the UUENCODE format, but we can override this default and send the attachment using Base 64 format by supplying the optional encodingmethod parameter to the AttachFile method.

objMail.AttachFile ("c:\images\logo.bmp", "Our logo", cdoEncodingBase64)
To set the encoding method for this attachment back to UUENCODE we would use the constant cdoEncodingUUEncode instead. Bear in mind that changing the encoding method for a NewMail object only affects that object. It does not alter the default method used for encoding new NewMail objects.

~Turbo
I need to eat my words. This works for me.
<%
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
     objNewMail.From = "server@mysite.com"
     objNewMail.To = "you@yoursite.com"
     objNewMail.Subject = "Test"
     objNewMail.Body = Now & vbcrlf
     objNewMail.BodyFormat = CdoBodyFormatText
     objNewMail.MailFormat = CdoMailFormatText
     objNewMail.Importance = CdoNormal
     objNewMail.AttachFile "D:\pathtofile\test.xsl"
     objNewMail.Send
     Set objNewMail = Nothing
     Dim objFSO
     Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set objFSO = Nothing
%>

Rick Halle
ASKER CERTIFIED SOLUTION
Avatar of RickHalle
RickHalle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now your all getting the picture....Remember "Anything" is possible somehow.

~Turbosig --> Happy Coding.
Avatar of kwk

ASKER

It seems, that the problem i had was in the process of making the XLS file, not in the way I sended the attachment.

The code you posted is just as valid as the original one I posted, i guess.

Thank you for working on this anyway.