Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email attachment problem

Status
Not open for further replies.

Pipe2Path

Programmer
Aug 28, 2001
60
I am trying to use CDO to email an excel document as an attachment. I retrieve the attachment from an email and am trying to forward it to someone else. I am able to retrieve the attachment from the original email, but when I go to send it out again, the excel file cannot be opened. It attaches it as a text file.


Here is my code :

Set objMessage = objICEEMail.Outbox.Messages.Add

'create message
objMessage.Subject = "Invoices"

'create attachment
Set objAttach = objMessage.Attachments.Add(objAttachment)
With objAttach
.Type = CdoFileData
.Position = 0 ' render at first character of message
End With

objMessage.Update

'create recipient
Set objRecipient = objMessage.Recipients.Add

'add recipients name
strRecipient = 'John Doe'
objRecipient.Name = Replace(strRecipient, "'", "")
objRecipient.Type = mapiTo
objRecipient.Resolve

objMessage.Update

'send message
objMessage.Send ShowDialog:=False

Thanks in advance.
 
I solved my own problem. I have to use the WriteToFile method to write to a temp folder on the hard drive, and then use the Source property when adding the attachment.

I wish there was a way to directly add the attachment as an object without going thru the intermediate step of copying the file to your hard drive.

If anyone know how, please post.

Thanks.
 
Hello,

This is what I use to add an attachment. Perhaps this will help.


Set objAttach = objMessage.Attachments.Add
With objAttach
.Name = "DaadMonitor2" & Date$ & ".doc"
.Type = mapiFileData
.Source = "c:\Logs\DaadMonitor2" & Date$ & ".doc"
.ReadFromFile FileName:="c:\Logs\DaadMonitor2" & Date$ & ".doc"
.Position = 3880
End With

"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top