Problem: need to preserve Customer's email signature in Outlook automation code. Tech: VFP9SP2 app using the latest Outlook client.
This is an update to the 8/21/2019 thread I started about using Outlook to create an email with file attachments. Got that code working (see below) but now need to find a way to preserve the customer's Outlook email signature. As the code is below, it creates a blank email and does NOT use their signature. I'm going to research this with fresh eyes tomorrow but wanted to throw this out in case others could chime in.
* start outlook LOCAL oOutlook as Outlook.Application, oNamespace as Outlook.NameSpace, oMailItem as Outlook.MailItem, lcFilename as String, lcRange as String, llOK as Logical, lcDir as String LOCAL oRecipient as Outlook.Recipient oOutlook = CREATEOBJECT("Outlook.Application") #DEFINE olFolderDisplayNormal 0 #DEFINE olMailItem 0 #DEFINE olCC 2 #DEFINE olBCC 3 #DEFINE olOriginator 0 #DEFINE olTo 1 oNameSpace = oOutlook.GetNameSpace("MAPI") oExplorer = oOutlook.Explorers.Add(oNameSpace.Folders[1],olFolderDisplayNormal) oMailItem = oOutlook.CreateItem(olMailItem) WITH oMailItem .Subject = ALLTRIM(this.txtSubject.Value) .Body = ALLTRIM(this.edtBody.Value) *** mjb 10/21/2019 - added defensive coding for L vs. N and empty too IF ((VARTYPE(this.chkEmail.Value)="L" AND this.chkEmail.Value) OR (VARTYPE(this.chkEmail.Value)="N" AND this.chkEmail.Value = 1)) AND NOT EMPTY(this.txtEmail.Value) THEN .Recipients.Add(ALLTRIM(this.txtEmail.Value)) ENDIF *** mjb 10/21/2019 - added CC IF ((VARTYPE(this.chkSRep.Value)="L" AND this.chkSRep.Value) OR (VARTYPE(this.chkSRep.Value)="N" AND this.chkSRep.Value = 1)) AND NOT EMPTY(this.txtSalesRepEmail.Value) THEN oRecipient = .Recipients.Add(ALLTRIM(this.txtSalesRepEmail.Value)) oRecipient.Type = olCC ENDIF * first add the built PDF from MergeDocuments above IF liCnt > 0 THEN .Attachments.Add(lcFile) ENDIF && liCnt > 0 * any non-PDFs to attach? SELECT curEmailThese SCAN FOR UPPER(JUSTEXT(cfilename)) <> "PDF" .Attachments.Add(ADDBS(ALLTRIM(curEmailThese.cpath))+ALLTRIM(curEmailThese.cfilename)) ENDSCAN
.Display() && Save() *.Send() ENDWITH
Try .GetInspector(). See my code below:
**Outlook automation **example from Ted Roche: C:\VFP_Extras\Outlook_Automation\ROC147 Automating Outlook with Visual FoxPro.mht **Hyperlink 'file:' suggested by Fred Taylor **.GetInspector, lcSig suggested by Fred Taylor 10/1/2010 LOCAL loOutlook as Outlook.Application, ; loNameSpace as Outlook.NameSpace, ; loFolder as Outlook.MAPIFolder, ; loMailItem as Outlook.MailItem
TRY loOutlook = CREATEOBJECT("Outlook.Application") CATCH MESSAGEBOX("Sorry, Outlook.Application is not available.",0+16,'Outlook.Application not available') ENDTRY IF TYPE("loOutlook")<>"O" MESSAGEBOX("Sorry, loOutlook is not an Object.",0+16,'loOutlook not an Object') endif local lcTO,lcCC,lcBCC store '' to lcTO,lcCC,lcBCC lcTo = [someone@somewhere.com] lcTo = CHRTRAN(lcTo, [,] , [;]) && change commas to semicolons, comma separators cause Outlook throw an error lcCC = CHRTRAN(lcCC, [,] , [;]) && Outlook errorcode: lcBCC = CHRTRAN(lcBCC, [,] , [;]) && Error# 1429, OLE IDispatch exception code 4096 from Microsoft Outlook: Outlook does not recognize one or more names. .. loNamespace = loOutlook.GetNamespace("MAPI") loFolder= loNamespace.GetDefaultFolder(4) && 3=Deleted Items, 4=Outbox, 5=Sent Items, 6=Inbox, 9=Calendar, 10=Contacts, 11=Journal, 12=Notes, 13=Tasks loMailItem = loFolder.Items.Add() WITH loMailItem .GetInspector() && Should load your default signature (among other things it does to your Mail item) lcSig = .HtmlBody && MUSt use HtmlBody if graphics in sig .SentOnBehalfOfName = 'someoneelse@here.com' && From, see: http://support.microsoft.com/kb/232309 .TO = lcTO .CC = lcCC .BCC = lcBCC .Subject = 'subject line' .Body = 'some text' lcFile = 'somepath\somefile.ext' IF FILE(lcFile) .Attachments.Add( lcFile) .HtmlBody= ALLTRIM( .HtmlBody) + CHR(13) + lcSig if pcDevelopment = "Y" .Display() else .Send() endif ENDIF ENDWITH
Customized Business Services, LLC (928) 580-6352 Dennis Schuette Primary: dennis@cbsds.com 49 NW 130 Avenue Alternate: Schuette.dennis@gmail.com Great Bend, KS 67530
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of MB Software Solutions, LLC Sent: Tuesday, December 03, 2019 10:17 PM To: profoxtech@leafe.com Subject: Programatically saving the Outlook signature when using automation code
Problem: need to preserve Customer's email signature in Outlook automation code. Tech: VFP9SP2 app using the latest Outlook client.
This is an update to the 8/21/2019 thread I started about using Outlook to create an email with file attachments. Got that code working (see below) but now need to find a way to preserve the customer's Outlook email signature. As the code is below, it creates a blank email and does NOT use their signature. I'm going to research this with fresh eyes tomorrow but wanted to throw this out in case others could chime in.
* start outlook LOCAL oOutlook as Outlook.Application, oNamespace as Outlook.NameSpace, oMailItem as Outlook.MailItem, lcFilename as String, lcRange as String, llOK as Logical, lcDir as String LOCAL oRecipient as Outlook.Recipient oOutlook = CREATEOBJECT("Outlook.Application") #DEFINE olFolderDisplayNormal 0 #DEFINE olMailItem 0 #DEFINE olCC 2 #DEFINE olBCC 3 #DEFINE olOriginator 0 #DEFINE olTo 1 oNameSpace = oOutlook.GetNameSpace("MAPI") oExplorer = oOutlook.Explorers.Add(oNameSpace.Folders[1],olFolderDisplayNormal) oMailItem = oOutlook.CreateItem(olMailItem) WITH oMailItem .Subject = ALLTRIM(this.txtSubject.Value) .Body = ALLTRIM(this.edtBody.Value) *** mjb 10/21/2019 - added defensive coding for L vs. N and empty too IF ((VARTYPE(this.chkEmail.Value)="L" AND this.chkEmail.Value) OR (VARTYPE(this.chkEmail.Value)="N" AND this.chkEmail.Value = 1)) AND NOT EMPTY(this.txtEmail.Value) THEN .Recipients.Add(ALLTRIM(this.txtEmail.Value)) ENDIF *** mjb 10/21/2019 - added CC IF ((VARTYPE(this.chkSRep.Value)="L" AND this.chkSRep.Value) OR (VARTYPE(this.chkSRep.Value)="N" AND this.chkSRep.Value = 1)) AND NOT EMPTY(this.txtSalesRepEmail.Value) THEN oRecipient = .Recipients.Add(ALLTRIM(this.txtSalesRepEmail.Value)) oRecipient.Type = olCC ENDIF * first add the built PDF from MergeDocuments above IF liCnt > 0 THEN .Attachments.Add(lcFile) ENDIF && liCnt > 0 * any non-PDFs to attach? SELECT curEmailThese SCAN FOR UPPER(JUSTEXT(cfilename)) <> "PDF" .Attachments.Add(ADDBS(ALLTRIM(curEmailThese.cpath))+ALLTRIM(curEmailThese.cfilename)) ENDSCAN
.Display() && Save() *.Send() ENDWITH
_______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech Searchable Archive: https://leafe.com/archives This message: https://leafe.com/archives/byMID/df8c1535-8e2f-7708-82c4-8d69907f4366@mbsoft... ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious. Report [OT] Abuse: http://leafe.com/reportAbuse/df8c1535-8e2f-7708-82c4-8d69907f4366@mbsoftware...
That did the trick! I was thinking .Body, not .HTMLBody. Thanks, Dennis!
On 12/4/2019 7:16 AM, Dennis Schuette wrote:
Try .GetInspector(). See my code below:
**Outlook automation **example from Ted Roche: C:\VFP_Extras\Outlook_Automation\ROC147 Automating Outlook with Visual FoxPro.mht **Hyperlink 'file:' suggested by Fred Taylor **.GetInspector, lcSig suggested by Fred Taylor 10/1/2010 LOCAL loOutlook as Outlook.Application, ; loNameSpace as Outlook.NameSpace, ; loFolder as Outlook.MAPIFolder, ; loMailItem as Outlook.MailItem
TRY loOutlook = CREATEOBJECT("Outlook.Application") CATCH MESSAGEBOX("Sorry, Outlook.Application is not available.",0+16,'Outlook.Application not available') ENDTRY IF TYPE("loOutlook")<>"O" MESSAGEBOX("Sorry, loOutlook is not an Object.",0+16,'loOutlook not an Object') endif local lcTO,lcCC,lcBCC store '' to lcTO,lcCC,lcBCC lcTo = [someone@somewhere.com] lcTo = CHRTRAN(lcTo, [,] , [;]) && change commas to semicolons, comma separators cause Outlook throw an error lcCC = CHRTRAN(lcCC, [,] , [;]) && Outlook errorcode: lcBCC = CHRTRAN(lcBCC, [,] , [;]) && Error# 1429, OLE IDispatch exception code 4096 from Microsoft Outlook: Outlook does not recognize one or more names. .. loNamespace = loOutlook.GetNamespace("MAPI") loFolder= loNamespace.GetDefaultFolder(4) && 3=Deleted Items, 4=Outbox, 5=Sent Items, 6=Inbox, 9=Calendar, 10=Contacts, 11=Journal, 12=Notes, 13=Tasks loMailItem = loFolder.Items.Add() WITH loMailItem .GetInspector() && Should load your default signature (among other things it does to your Mail item) lcSig = .HtmlBody && MUSt use HtmlBody if graphics in sig .SentOnBehalfOfName = 'someoneelse@here.com' && From, see: http://support.microsoft.com/kb/232309 .TO = lcTO .CC = lcCC .BCC = lcBCC .Subject = 'subject line' .Body = 'some text' lcFile = 'somepath\somefile.ext' IF FILE(lcFile) .Attachments.Add( lcFile) .HtmlBody= ALLTRIM( .HtmlBody) + CHR(13) + lcSig if pcDevelopment = "Y" .Display() else .Send() endif ENDIF ENDWITH
Customized Business Services, LLC (928) 580-6352 Dennis Schuette Primary: dennis@cbsds.com 49 NW 130 Avenue Alternate: Schuette.dennis@gmail.com Great Bend, KS 67530
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of MB Software Solutions, LLC Sent: Tuesday, December 03, 2019 10:17 PM To: profoxtech@leafe.com Subject: Programatically saving the Outlook signature when using automation code
Problem: need to preserve Customer's email signature in Outlook automation code. Tech: VFP9SP2 app using the latest Outlook client.
This is an update to the 8/21/2019 thread I started about using Outlook to create an email with file attachments. Got that code working (see below) but now need to find a way to preserve the customer's Outlook email signature. As the code is below, it creates a blank email and does NOT use their signature. I'm going to research this with fresh eyes tomorrow but wanted to throw this out in case others could chime in.
* start outlook LOCAL oOutlook as Outlook.Application, oNamespace as Outlook.NameSpace, oMailItem as Outlook.MailItem, lcFilename as String, lcRange as String, llOK as Logical, lcDir as String LOCAL oRecipient as Outlook.Recipient oOutlook = CREATEOBJECT("Outlook.Application") #DEFINE olFolderDisplayNormal 0 #DEFINE olMailItem 0 #DEFINE olCC 2 #DEFINE olBCC 3 #DEFINE olOriginator 0 #DEFINE olTo 1 oNameSpace = oOutlook.GetNameSpace("MAPI") oExplorer = oOutlook.Explorers.Add(oNameSpace.Folders[1],olFolderDisplayNormal) oMailItem = oOutlook.CreateItem(olMailItem) WITH oMailItem .Subject = ALLTRIM(this.txtSubject.Value) .Body = ALLTRIM(this.edtBody.Value) *** mjb 10/21/2019 - added defensive coding for L vs. N and empty too IF ((VARTYPE(this.chkEmail.Value)="L" AND this.chkEmail.Value) OR (VARTYPE(this.chkEmail.Value)="N" AND this.chkEmail.Value = 1)) AND NOT EMPTY(this.txtEmail.Value) THEN .Recipients.Add(ALLTRIM(this.txtEmail.Value)) ENDIF *** mjb 10/21/2019 - added CC IF ((VARTYPE(this.chkSRep.Value)="L" AND this.chkSRep.Value) OR (VARTYPE(this.chkSRep.Value)="N" AND this.chkSRep.Value = 1)) AND NOT EMPTY(this.txtSalesRepEmail.Value) THEN oRecipient = .Recipients.Add(ALLTRIM(this.txtSalesRepEmail.Value)) oRecipient.Type = olCC ENDIF * first add the built PDF from MergeDocuments above IF liCnt > 0 THEN .Attachments.Add(lcFile) ENDIF && liCnt > 0 * any non-PDFs to attach? SELECT curEmailThese SCAN FOR UPPER(JUSTEXT(cfilename)) <> "PDF" .Attachments.Add(ADDBS(ALLTRIM(curEmailThese.cpath))+ALLTRIM(curEmailThese.cfilename)) ENDSCAN
.Display() && Save() *.Send() ENDWITH
[excessive quoting removed by server]
Here's another tip I saw using the Scripting.FileSystemObject: https://www.rondebruin.nl/win/s1/outlook/signature.htm
On 12/4/2019 7:16 AM, Dennis Schuette wrote:
Try .GetInspector(). See my code below:
**Outlook automation **example from Ted Roche: C:\VFP_Extras\Outlook_Automation\ROC147 Automating Outlook with Visual FoxPro.mht **Hyperlink 'file:' suggested by Fred Taylor **.GetInspector, lcSig suggested by Fred Taylor 10/1/2010 LOCAL loOutlook as Outlook.Application, ; loNameSpace as Outlook.NameSpace, ; loFolder as Outlook.MAPIFolder, ; loMailItem as Outlook.MailItem
TRY loOutlook = CREATEOBJECT("Outlook.Application") CATCH MESSAGEBOX("Sorry, Outlook.Application is not available.",0+16,'Outlook.Application not available') ENDTRY IF TYPE("loOutlook")<>"O" MESSAGEBOX("Sorry, loOutlook is not an Object.",0+16,'loOutlook not an Object') endif local lcTO,lcCC,lcBCC store '' to lcTO,lcCC,lcBCC lcTo = [someone@somewhere.com] lcTo = CHRTRAN(lcTo, [,] , [;]) && change commas to semicolons, comma separators cause Outlook throw an error lcCC = CHRTRAN(lcCC, [,] , [;]) && Outlook errorcode: lcBCC = CHRTRAN(lcBCC, [,] , [;]) && Error# 1429, OLE IDispatch exception code 4096 from Microsoft Outlook: Outlook does not recognize one or more names. .. loNamespace = loOutlook.GetNamespace("MAPI") loFolder= loNamespace.GetDefaultFolder(4) && 3=Deleted Items, 4=Outbox, 5=Sent Items, 6=Inbox, 9=Calendar, 10=Contacts, 11=Journal, 12=Notes, 13=Tasks loMailItem = loFolder.Items.Add() WITH loMailItem .GetInspector() && Should load your default signature (among other things it does to your Mail item) lcSig = .HtmlBody && MUSt use HtmlBody if graphics in sig .SentOnBehalfOfName = 'someoneelse@here.com' && From, see: http://support.microsoft.com/kb/232309 .TO = lcTO .CC = lcCC .BCC = lcBCC .Subject = 'subject line' .Body = 'some text' lcFile = 'somepath\somefile.ext' IF FILE(lcFile) .Attachments.Add( lcFile) .HtmlBody= ALLTRIM( .HtmlBody) + CHR(13) + lcSig if pcDevelopment = "Y" .Display() else .Send() endif ENDIF ENDWITH
Customized Business Services, LLC (928) 580-6352 Dennis Schuette Primary: dennis@cbsds.com 49 NW 130 Avenue Alternate: Schuette.dennis@gmail.com Great Bend, KS 67530
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of MB Software Solutions, LLC Sent: Tuesday, December 03, 2019 10:17 PM To: profoxtech@leafe.com Subject: Programatically saving the Outlook signature when using automation code
Problem: need to preserve Customer's email signature in Outlook automation code. Tech: VFP9SP2 app using the latest Outlook client.
This is an update to the 8/21/2019 thread I started about using Outlook to create an email with file attachments. Got that code working (see below) but now need to find a way to preserve the customer's Outlook email signature. As the code is below, it creates a blank email and does NOT use their signature. I'm going to research this with fresh eyes tomorrow but wanted to throw this out in case others could chime in.
* start outlook LOCAL oOutlook as Outlook.Application, oNamespace as Outlook.NameSpace, oMailItem as Outlook.MailItem, lcFilename as String, lcRange as String, llOK as Logical, lcDir as String LOCAL oRecipient as Outlook.Recipient oOutlook = CREATEOBJECT("Outlook.Application") #DEFINE olFolderDisplayNormal 0 #DEFINE olMailItem 0 #DEFINE olCC 2 #DEFINE olBCC 3 #DEFINE olOriginator 0 #DEFINE olTo 1 oNameSpace = oOutlook.GetNameSpace("MAPI") oExplorer = oOutlook.Explorers.Add(oNameSpace.Folders[1],olFolderDisplayNormal) oMailItem = oOutlook.CreateItem(olMailItem) WITH oMailItem .Subject = ALLTRIM(this.txtSubject.Value) .Body = ALLTRIM(this.edtBody.Value) *** mjb 10/21/2019 - added defensive coding for L vs. N and empty too IF ((VARTYPE(this.chkEmail.Value)="L" AND this.chkEmail.Value) OR (VARTYPE(this.chkEmail.Value)="N" AND this.chkEmail.Value = 1)) AND NOT EMPTY(this.txtEmail.Value) THEN .Recipients.Add(ALLTRIM(this.txtEmail.Value)) ENDIF *** mjb 10/21/2019 - added CC IF ((VARTYPE(this.chkSRep.Value)="L" AND this.chkSRep.Value) OR (VARTYPE(this.chkSRep.Value)="N" AND this.chkSRep.Value = 1)) AND NOT EMPTY(this.txtSalesRepEmail.Value) THEN oRecipient = .Recipients.Add(ALLTRIM(this.txtSalesRepEmail.Value)) oRecipient.Type = olCC ENDIF * first add the built PDF from MergeDocuments above IF liCnt > 0 THEN .Attachments.Add(lcFile) ENDIF && liCnt > 0 * any non-PDFs to attach? SELECT curEmailThese SCAN FOR UPPER(JUSTEXT(cfilename)) <> "PDF" .Attachments.Add(ADDBS(ALLTRIM(curEmailThese.cpath))+ALLTRIM(curEmailThese.cfilename)) ENDSCAN
.Display() && Save() *.Send() ENDWITH
[excessive quoting removed by server]
Preserving the Outlook signature is a crapshoot in my experience, and only seems to consistently work when using extended MAPI to automate Outlook.