Avatar of justaphase
justaphase
Flag for Portugal

asked on 

FoxPro send email Outlook.Application with signature

Hi Experts,

I've been struggling allot with this..
I have a foxpro code that works fine opening a new outlook email and attaching a file and everything, the problem stands with the signature.

I tried to get the original html that Outlook.Application generates in the html body of the email with the signature and add some text to it (since the problem is when we set the .BodyHtml, the signature that is set by default is overwritten), but scrambles everything and i don't know why.

So googling it, i've found out that the best way is to get signature in the appdata system folder witch is in html, rtf and txt format and add it to the html body of the email.

the problem is that the images of the signature aren't embedded (doesn't show them, appears a box saying that the image can't be displayed) and when i try to send the email, Outlook doesn't let me saying "Could not complete the operation, One or more parameter values are not valid".

What am i doing wrong?
Please help me.

My code:
PROCEDURE EnviaEmailBOCl
	LPARAMETERS EmailCl, Assunto, Texto, Ficheiro
	LOCAL EnviaOk
	EnviaOk = .t.
	
	
	IF EnviaOk
	
		#DEFINE MAILITEM 0
		#DEFINE IMPORTANCELOW 0
		#DEFINE IMPORTANCENORMAL 1
		#DEFINE IMPORTANCEHIGH 2
		
		oOutLookObject = CreateObject("Outlook.Application")
		oEmailItem = oOutLookObject.CreateItem(MAILITEM)
		
		oOutLookObject = oEmailItem.GetInspector
		
		ADIR(aHtmSig,GETENV("APPDATA")+"\Microsoft\Signatures\*.htm")
		
		xfile = GETENV("APPDATA")+"\Microsoft\Signatures\"+aHtmSig(1,1)
		x= FILETOSTR(xfile)
		
		WITH oEmailItem
		   .Recipients.Add(EmailCL) && uses the Recipients collection
		   &&.CC="assistente@acidados.pt"
		   .Subject = Assunto
		   .Importance = IMPORTANCENORMAL
		   **.Display()
		   .HtmlBody = "Adding text!!<br>" + x
		   .Attachments.Add(Ficheiro) && Note that the fully qualified path and file is required.
		   **.Send
		   .Display
		ENDWITH
		
		RELEASE oEmailItem
		RELEASE oOutLookObject
	
	ENDIF

ENDPROC

Open in new window

FoxPro

Avatar of undefined
Last Comment
justaphase

8/22/2022 - Mon