1. Moshe Tangi
  2. PowerBuilder
  3. Wednesday, 25 September 2019 12:02 PM UTC

Hi all,

I am using  outlook by OLE from within my PB application. ( 2017 r3 build 1858 )

I am setting all the parameters like : to , body , attach ..

I want to add the user default signature as he configured within the outlook

Does any one have an idea ?

 

Thanks

Moshe

 

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 25 September 2019 19:30 PM UTC
  2. PowerBuilder
  3. # 1

We do something similar:

We read the signatures from the folder (according to office version, language used in office, etc.) from this folder:

"C:\Users\..your user name ...\AppData\Roaming\Microsoft\Signatures" (for Spanish Office it would end on "....\firmas" )" 

When you have created previously a signature with / in Outlook, it has been saved in that folder with different formats:

- txt

- html

- rtf

1) We read the .RTF file of the chosen signature from disk from previously mentioned folder (not sure how to know which one is the DEFAULT, but must be in the registry I guess, we simply save the last one used as default in a table).

2) Then paste that contents of the file at the end of an email that a user is writing in an RTE control.

3) Then do a SaveDocument with Html format, something like "rte_notedet.SaveDocument( ls_tempFileName, FileTypeHTML!, EncodingAnsi!)"

4) Read that html from disk and use it as the Body for the email we finally send.

 

Comment
  1. Tracy Lamb
  2. Wednesday, 28 June 2023 15:19 PM UTC
Hi Miguel, this is a very old post so not sure you'll see my message... how do I get the user name to find the signature file?

~~~Tracy
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 25 September 2019 12:57 PM UTC
  2. PowerBuilder
  3. # 2

Are you sure you aren't overwriting it when you set HTMLBody?

Here is a vbscript I found:

Dim OApp As Object, OMail As Object, signature As String
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
    With OMail
    .Display
    End With
        signature = OMail.body
    With OMail
    '.To = "someone@somedomain.com"
    '.Subject = "Type your email subject here"
    '.Attachments.Add
    .body = "Add body text here" & vbNewLine & signature
    '.Send
    End With
Set OMail = Nothing
Set OApp = Nothing
Comment
  1. Moshe Tangi
  2. Wednesday, 25 September 2019 13:34 PM UTC
hi Roland ,

It looks so simple , I tried it but does not work

Thanks
  1. Helpful
  1. David Peace (Powersoft)
  2. Wednesday, 25 September 2019 13:48 PM UTC
Looking at that example it is getting the default body from the email at the start:

signature = OMail.body

If that does not work then I cannot see how you would get the signature content.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 25 September 2019 18:19 PM UTC
  2. PowerBuilder
  3. # 3

Hi, Moshe -

Unfortunately, the Outlook OLE Object Model does not support signatures - So it looks to be a pain in the patoot to do what you are asking. The signature files (in .txt, .rtf & .htm formats for each signature defined within Outlook) reside in the \Microsoft\Signatures folder, which typically translates to the C:\Users\\AppData\Roaming\Microsoft\Signatures folder.

The difficult question to answer is how to determine which set of signature files (a user can define multiple signatures) is to be used to send new emails? It looks like the info is in the Windows Registry under HKEY_CURRENT_USER\Software\Microsoft\Office\... but the subkey sequence after that point is cryptic & problematic. I found mine by creating a uniquely-named signature in Outlook > Options > Email, then performing a Registry search using regedit.exe. At some point in the subkey hierarchy, you'll find a string data value named "New Signature" (signature to be used with new emails), and its data value is the filename of the 3 files in the aforementioned AppData Signatures folder.

Once you determine if the user has a signature defined for new emails, and the name of the signature file, you'll need to read the contents of the appropriate format file and append the contents to the end of MailItem body.

I hope this helps you develop a solution.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 25 September 2019 19:38 PM UTC
  2. PowerBuilder
  3. # 4

Right now I'm working on my "own" Richtext, as we also want to be able to paste images in the body and use company logos in the signatures.

Appeon's RTE sometimes embeds the pasted image, depending on where you pasted it from. (there's a difference between a copied image after opening it from for example Paint.exe and one copied from the windows snipping tool). When you save the document, if the image has been embedded I don't know how to separate it from the html. When SaveDocument did manage to write it's temporary images, you can then read those from disk and add them as linked images in the html body. To be able to send that correctly you would also have to attach those temporary images as "hidden" attachments, for the end user on the receiving site to be able to see them.

I hope that I'll have some time within a few months to end that work (not a priority now) and then separate our email object somehow into a small demo application so everyone can use it and maybe improve it.

(Right now I'm simply too busy and have made promises before I couldn't keep, so ... don't wait for it).

Comment
  1. Moshe Tangi
  2. Thursday, 26 September 2019 06:21 AM UTC
Hi Miguel

I am not waiting ...but it could be great to see your work on it .

Thanks
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 26 September 2019 09:21 AM UTC
Haha, ok, I'll try to apply myself a bit. The problem will be to rip out all the Company and PFC dependencies. Still it's going to take at least some weeks.



What I CAN do, is let go of the initial, very badly coded and incomplete ActiveX control that I'm working on. (this weekend). It's based on the work of others who know a lot more C# and .Net than me. For now I'm just trying to get my images to be included properly in my emails. Once that works I'll have a look at how to drastically strip down the code.

Instead of waiting to release something "perfect" or at least "fully finished" I'll try to publish it on my GitLab this weekend (which is another little learning curve for me).



The "work of others" that I'm speaking of are these 2 great code projects:

First project:

---

To convert RTF to HTML with export of images to disk:

I found this link https://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter in "answer 8" of this page:

https://stackoverflow.com/questions/32224148/converting-rtf-format-to-html-tags



Project 2:

---

To adapt with my own functions to call from PB and make use of the first project (mentioned here above):

https://www.codeproject.com/articles/24443/richertextbox

In the demo project code there should be an explanation somewhere on how to call the conversion functions. For now I'm just calling the program as done in the demo mode, without really directly passing in the rtf contents. I first write it to disk, but in the future I'll try to improve that process, as it should not be needed.

I'm not totally sure yet if the images are "always" saved correctly but sofar it looks good.



I think that we're allowed to use the code freely.

  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 28 June 2023 17:18 PM UTC
  2. PowerBuilder
  3. # 5

Hi Tracy,

As an answer to your question, we do something like this to get the foldername with signature files in it. We only use the RTF formatted ones BTW:

if is_pathSignatures = "" then
	// try to get path but only if setting is OUTLOOK or OUTLOOK64 and version of office >= 2007:
	if Upper(gnv_app.is_mailsystem) = 'OUTLOOK64' or Upper(gnv_app.is_mailSystem) = 'OUTLOOK' then
		if is_pathSignatures = "" then
			//Office 97   -  7.0
			//Office 98   -  8.0
			//Office 2000 -  9.0
			//Office XP   - 10.0
			//Office 2003 - 11.0
			//Office 2007 - 12.0 
			//Office 2010 - 14.0 (sic!)
			//Office 2013 - 15.0
			//Office 2016 - 16.0
			if gnv_app.ii_officeVersion > 11 then
				is_pathSignatures = gnv_app.of_GetFolderPath(CSIDL_APPDATA)
				// see if English Outlook installed:
				is_pathSignatures += '\Microsoft\Signatures' 
				if NOT FileExists(is_pathSignatures) then
					is_pathSignatures = ""
				end if
				// see if Spanish Outlook installed:
				if is_pathSignatures = "" then
					is_pathSignatures = gnv_app.of_GetFolderPath(CSIDL_APPDATA)
					is_pathSignatures += '\Microsoft\Firmas' 
					if NOT FileExists(is_pathSignatures) then
						is_pathSignatures = ""
					end if
				end if
				// see if Italian Outlook installed:
				if is_pathSignatures = "" then
					is_pathSignatures = gnv_app.of_GetFolderPath(CSIDL_APPDATA)
					is_pathSignatures += '\Microsoft\Firme' 
					if NOT FileExists(is_pathSignatures) then
						is_pathSignatures = ""
					end if
				end if
				
			end if
		end if
	end if
end if

So basically we look at the folder %APPDATA% and concatenate it with '\Microsoft\Signatures'. Note that 'Signatures' for some crazy reason can be in different languages.

Let me know if you need more help.

regards.

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.