Search code examples
pythongoogle-apigmail-api

How to change email signature using GMAIL API?


I want to setup email signature for each user in the domain. The thing is I already have a html signature ready but I dont know how to use html signature with GMAIl API. I am using python and when I try to do that, it only converts it to text. Is there any way to embed html signature in a variable which then inserts into the gmail account using GMAIl API?


Solution

  • Thanks for the reply. I found the solution to use html signatures. What I did is created html files using python script (You can also create them in any other way. I just did using python because I wanted a single script to create a html signature as well as change the email signature for the user).

    And then imported whole html as text inside a python variable as shown below.

    file = open(test.html, 'r')
        htmlfile = file.read()
        ESignature = {'signature': htmlfile}
    

    After that in the email signature body parameter I just used the variable where I stored the html signature and it worked.

    sig = service.users().settings().sendAs().update(userId='me', sendAsEmail="[email protected]", body=ESignature).execute()