How to retrive Outlook default signature

The Outlook signatures are stored in the %APPDATA%\Microsoft\Signatures\ folder in text, RTF and HTML formats.
In case of multiple signatures, the default can be found through Word automation. Tested in Outlook 2003 and later.

This is sample code. Add error handling and adjust to your requirements as necessary.

* The folder name where signatures are stored depends on the Windows language version
* English
lcFilePath = GETENV("APPDATA") + "\Microsoft\Signatures\"
* Spanish 
*lcFilePath = GETENV("APPDATA") + "\Microsoft\Firmas\"
 
loWord = CREATEOBJECT("Word.Application")
loEmOpt = loWord.EmailOptions
loOlSig = loEmOpt.EmailSignature
lcSigFileName = ALLTRIM(loOlSig.NewMessageSignature )
* Text signature
lcPathAndFile = lcFilePath + lcSigFileName + ".txt"
IF FILE(lcPathAndFile )
	lcTextIn = FILETOSTR(lcPathAndFile  )
 
	IF  LEFT( lcTextIn ,2) = 0hFFFE
		* Remove Unicode header
		lcTextIn = SUBSTR(lcTextIn,3)		
	ENDIF	
 
	lcFileContent = STRCONV(lcTextIn ,6)	
	? lcFileContent 
ENDIF

Comments

* FIX for Spanish version of Windows
lcFilePath = GETENV("APPDATA") + "\Microsoft\Signatures\"
loWord = CREATEOBJECT("Word.Application")
loEmOpt = loWord.EmailOptions
loOlSig = loEmOpt.EmailSignature
lcSigFileName = ALLTRIM(loOlSig.NewMessageSignature )
* Text signature
lcPathAndFile = lcFilePath + lcSigFileName + ".txt"
? lcPathAndFile
IF NOT FILE(lcPathAndFile )
	lcPathAndFile = Strtran(lcPathAndFile,"\Signatures\","\Firmas\")
	? lcPathAndFile
EndIf 	
IF FILE(lcPathAndFile )
	lcTextIn = FILETOSTR(lcPathAndFile  )
 
	IF  LEFT( lcTextIn ,2) = 0hFFFE
		* Remove Unicode header
		lcTextIn = SUBSTR(lcTextIn,3)		
	ENDIF	
 
	lcFileContent = STRCONV(lcTextIn ,6)	
	? lcFileContent 
EndIf

Thanks, I adjusted the code per your suggestion.

Hi,

I'm failry new to scripting. I'm trying to convert this to powershell.

I have used the following script but that does not work, any help is appreciated.

$MSWord = New-Object -com word.application
$EmailOptions = $MSWord.EmailOptions
$EmailSignature = $EmailOptions.EmailSignature
$EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
$display = $EmailSignature.NewMessageSignature
Write-Host "Signature name is $display"
$MSWord.Quit()

Thanks,

John

any script in POWERSHELL ?

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.