Thanks for the compliment!
Thanks for the compliment!
I Looked a little closer at the CDO documents on MSDN (
and
I couldn't find any reference to the "AddAttachment" that you mention... instead it seems that CDO uses the .Add method of the .Attachments collection on a message object.
It seems that you want to create an attachment object, then change its "name" property.
Basing this on Mike Gagnon's faq1251-4969, and the MSDN articles cited above, you could do something like this following code, however, this code doesn't work with the version of CDO that is on my computer... it seems to be mixing versions of CDO. So, look more at the second code sample below...
Code:
iMsg = Createobject("CDO.Message")
iConf = Createobject("CDO.Configuration")
Flds = iConf.Fields
With Flds
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = 'Your SMTP server name here'
.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
.Update
Endwith
With iMsg
.Configuration = iConf
.To = "me@hotmail.com"
.CC = ""
.BCC = ""
.From = "me@somewhere.com"
.Subject = "This is a test"
.TextBody = "This is the body text"
oAttach = .Attachments.Add()
oAttach.Source = "C:\local path\UTILIZATION_CM200501.PDF"
oAttach.Name = "January 2005 Current Month Utilization.pdf"
* or use this:
* .Attachments.Add( "January 2005 Current Month Utilization.pdf",,,"C:\local path\UTILIZATION_CM200501.PDF")
.Send
ENDWITH
oAttach = .NULL.
iMsg = .Null.
iConf = .Null.
I looked further, and found that instead of using CDO.Message, if I used CDONTS.Session as a starting point, I got objects that more closely matched the MSDN documents.
So, this seems to work:
Code:
objSession = CreateObject ("CDONTS.Session")
* I don't know what you need to specify to logon successfully....
objSession.LogonSMTP('me','me@here.com')
objOutBox = objSession.Outbox()
oMsg = objOutbox.Messages.add()
oAttch = oMsg.Attachments.Add
oAttch.Name = 'whatever'
oAttach.Source = "C:\local path\UTILIZATION_CM200501.PDF"
oMsg.Send
I hope this gets you a bit further...
- Bill
Get the best answers to your questions -- See FAQ481-4875.