2

I have written a program which opens a .oft file from shared drive and puts desired email id in TO field and can edit the subject field as well. But at the end when the mail gets Displayed, my default signature always get added. Now I am going to deploy this script to multiple users and the mail does not need to have a user's signature as the template already has a groups signature predefined.

I already search and found that there is no mail.Signature in Outlook by which it can be modified.

import win32com.client as win32  


outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItemFromTemplate(r'\\Server\Share\Folder\maial.oft')
mail.To = 'someone@exapmle.com'
mail.Subject = 'Test'
mail.Display(True)

Is there any way by which I can restrict outlook to add the default signature in the mail using python ?

RJ.
  • 21
  • 1
  • 6

2 Answers2

0

The signatures are being kept as separate files in the Signatures folder. You can find this folder in the following location:

  • Windows XP
     C:\Documents and Settings\%username%\Application Data\Microsoft\Signatures
  • Windows Vista, Windows 7, Windows 8 and Windows 10
     C:\Users\%username%\AppData\Roaming\Microsoft\Signatures

To see this folder you must have View hidden files and folders enabled or you can simply copy and paste the above paths in the address bar in Explorer to directly open the folder.

You can read signatures from the folder specified and find them in the message body (see the HTMLBody property), so you will know what exactly should be deleted.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • But how would that help me in removing signature form mail open through python script. I cannot delete the signature as I have to use it for my regular mails. – RJ. Aug 01 '19 at 09:56
  • You can read signatures from the folder specified and find them in the message body (see the `HTMLBody` property), so you will know what exactly should be deleted. – Eugene Astafiev Aug 01 '19 at 11:37
  • I already tried printing the mail.HTMLBody, but it does not contain any thing related to the signature which could be deleted. – RJ. Aug 01 '19 at 13:16
  • The signature may not provide any indicators. You need to try to extract a piece listed in the signatures folder from the `HTMLBody` string. – Eugene Astafiev Aug 01 '19 at 13:29
0

As the signature is part of the whole email body (.HTMLbody), I realised I can 'initialize' it with a blank and just 'come back' to it with the desired content. This is especially helpful if you are using .GetInspector which, by default, always includes the designated email signature for the active outlook user account.

So you can do:

mail.HTMLbody = ''

and then

mail.HTMLbody = '<Insert desired content>' #This overwrites the previous one

and/or paste something via .GetInspector like a Word Document content for example:

msg.GetInspector.WordEditor.Range(Start=0, End=0).Paste() #This seems to append, not overwrite

For more about copying Word documents into Outlook, see this post.

-EDIT-

Since OP is using a template, it seems that the email signature is within the template itself (not being called by Outlook via .GetInspector --- which was my actual case), two possible solutions I can think of is to

  1. Get rid of it by creating a copy without the sig, then send that modified copy into Outlook.

  2. Continue using the template but specify the range (excluding the email sig) via .GetInspector

jNsatiable
  • 119
  • 3
  • 15