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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't send attachment filename as a 'variable' 1

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi,

I seem to be having a problem sending an attachment as a 'variable" and not a literal. When I send it as a literal, it works perfectly. When I assign a variable to the filename I want to send, it gives me an error.

Here is the simple codeline:

STORE SYS(5)+CURDIR()+ALLTRIM(m.aname) TO m.faname
Local iMsg,iConf
Declare SHORT InternetGetConnectedState In wininet.Dll;
INTEGER @lpdwFlags, Integer dwReserved
lConnect=displayState()
If lConnect
iMsg = Createobject("CDO.Message")
iConf = Createobject("CDO.Configuration")
Flds = iConf.Fields
With Flds
.Item(" = 2
.Item(" = '???.???.??.?' &&Brutus
.Item(" = 25
.Update()
Endwith
With iMsg
.Configuration = iConf
.To = "me@me.com"
.CC = ""
.BCC = ""
.From = "Byou@you.ca"
.Subject = "Weekly CDR's"
.Fields("Priority").Value = 0 && -1=Low, 0=Normal, 1=High
.Fields.Update()
.HTMLBody = "Hi,<BR>"+"<BR>Attached you will find your Weekly CDR's.<BR><BR>"
.AddAttachment =m.faname &&&&&& THIS IS WHERE IT CRASHES !!
.Send()
Endwith
iMsg = .Null.
iConf = .Null.
Flds = .Null.
Else
Messagebox("Could not send the message, your internet connection is down.")
Endif
Procedure displayState
Local lConnected
lConnected = .F.
lpdwFlags = 0
If InternetGetConnectedState (@lpdwFlags, 0) = 1
lConnected = .T.
Endif
Return lConnected
Endproc
 
error message is:

OLE IDispatch exception code 0 from CDO.Message.1: The system cannot find the specified file


As mentioned, it crashes here:

.AddAttachment =m.faname &&&&&& THIS IS WHERE IT CRASHES !!

If I put the literal path name it goes thru but doesn't like the variables.

Any help please.

Thanks,
FOXUP
 
Mike,

Yes sir, m.faname is the correct file and path name as it does exist.


Nigel,

Error = "Member not found"


Note for Nigel: I don't think you can put an '=' (equal sign in that particular statement). FYI, I tried it without as well and it gies me "Syntax Error".


Any help please.

Thanks,
FOXUP!
 
AddAttachment rather sounds like the name of a method, not a property. Then you need to pass parameters in paranthesis:

.AddAttachment(m.faname)

And intellisense tells me the CDO.Message object wants a URL here, not a file name, so try to URLize the name as a file:// url. That also means url escaping several characters, eg spaces in the filename need to be translated to %20.

Bye, Olaf.
 
.AddAttachment(m.faname) doesn't work.

Neither does URLizing it.

Any other options please.


Thanks,
FOXUP!
 
OK, let's put it this way.

This works:

.AddAttachment ("C:\Users\FOXUP\Desktop\Weeklies\alt20120119.xls")


works perfectly exactly as-is

BUT


STORE SYS(5)+CURDIR()+ALLTRIM(m.aname) TO m.faname
.AddAttachment =m.faname

nor does
.AddAttachment m.faname

nor does
.AddAttachment (&m.faname)
doesn't.

I'm not seeing why. Maybe it's the freezinf cold that's frozen my brain but I'm just not seeing it.


Any help is greatly appreciated.

Thanks,
FOXUP
 
1. What does file(m.faname) tell you?

2. this works for me:

Code:
m.cFilename = Addbs(GetEnv("TEMP"))+Sys(2015)
StrToFile("test",cFilename)
oCDOMessage = CreateObject("CDO.Message")
oCDOMessage.AddAttachment(m.cFilename)
? oCDOMessage.Attachments.Count

This displays 1, a sign the attachment was successfully attached. I also can get back the file via oCDOMessage.Attachments.Item(1).SaveToFile(filename)

If that sample does not work for you, that may have to do with your configuration, the method has two further parameters of user and password, which means it also can be a rights issue.

Bye, Olaf.
 
In my watch window for that
file(m.faname)

it says:

"C:\USERS\FOXUP\DESKTOP\WEEKLIES\Alt20121019.xls"

you think the upper has anything to do with it??

I really doubt it but anything is possible. The fqpn looks the same to me.

still doesn't work.


anything else?


Thanks,
FOXUP

 
my aplogies ... i copied and pasted your line without reading it...

i meant

.AddAttachment(fullpath(m.faname))

n
 
STORE SYS(5)+CURDIR()+ALLTRIM(m.aname) TO m.faname
.AddAttachment =m.faname

nor does
.AddAttachment m.faname

nor does
.AddAttachment (&m.faname)
doesn't.

You haven't included the one possibility that Olaf suggested:

Code:
.AddAttachment(m.faname)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,

The one possiblity doesn;t work either,

Nigel,

Sorry, no-go for that one too.

Olaf,

The sample you added does work.

Why doesn't my code work??

I'm really truly stumped.


Any other help please.


Thanks,
J
 
Olaf,

I'll use your code & work around it.

I'll give you the star and thank everybody for all their help but I'm still at a loss.


Nonetheless, thanks to all.


FOXUP!
 
I don't know why you're still at a loss, I already said it could be due to the config or a rights issue, as AddAttachment has user and password parameters...
But if the sample I added works, there is something wrong with your filename. It is not the upper case, that hurts, that's also true for the file name my sample script genereates.

You didn't say what File(m.faname) returned. Are you having the XLS file opened at the time you make the attachment? That may be an issue.

one more time:
Code:
With iMsg
* ...
  .Fields.Update()
  .HTMLBody = "Hi,<BR>"+"<BR>Attached you will find your Weekly CDR's.<BR><BR>"
  If Not Adir(laDummy,m.faname)>0
     Messagebox("the file is not on disc")
  Else
     .AddAttachment(m.faname)
  Endif
  .Send()
Endwith

You might try if doing without the WITH...ENDWITH works. I know you can use it with OLE onjects too, but that is one difference to my sample.

Bye, Olaf.
 
Im no Expert just a begginer actually

but this worked for me its a bit different

#DEFINE olFolderInbox 6
#DEFINE olFolderOutbox 4
#DEFINE olMailItem 0
#DEFINE olRecipient 4
#DEFINE olRecipients 17
#DEFINE IMPORTANCENORMAL 1

loApp=CreateObject("Outlook.Application")
loNamespace = loApp.GetNamespace("MAPI")
loFolder = loNamespace.GetDefaultFolder(olFolderInbox)
loEMailItem = loFolder.Items.Add(olMailItem)
loEmailitem.To = customers.email
*!* loEmailitem.cc = "myemail@something.ca"
loEmailItem.Subject = "My Email"
loEmailItem.body = "This email was sent to you using my VFP program I just Developed"
loEmailitem.Attachments.Add(m.cFileName)
loEmailItem.Importance = IMPORTANCENORMAL
loemailitem.Display()
release loApp, loEmailItem

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top