Search code examples
node.jsgmail-api

Fetch Email Signature using googleAPI


I am using googleAPI and Nodejs to fetch mails in details using oauth2.0. But I am not getting email's signature with image attached format. What is API to fetch incoming email with signature as image attached format?


Solution

  • A signature as an image is incorporated by Gmail not as an attachment or inline image, but rather as a download link assigned to img src within the text/html of your message body.

    Here a snippet of the response you obtain if you log the body of the message retrieved in raw format (the domain name and file ID replaced with XXX for privacy reasons):

    Content-Type: text/html; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable
    
    <div dir=3D"ltr"><br clear=3D"all"><div><div dir=3D"ltr" class=3D"gmail_sig=
    nature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><img src=3D"htt=
    ps://drive.google.com/a/XXXXXXXXXXXXXXXXX/uc?id=3DXXXXXXXXXXXXXXXXXX=
    sYV-&amp;export=3Ddownload"><br></div></div></div></div>
    

    Keep in mind that the URL is quoted-printable encoded. You need to remove the soft line breaks = and replace =3D by = to obtain the correct URL - something like

    https://drive.google.com/a/XXXXXXXXXXXXXXXXX/uc?id=XXXXXXXXXXXXXXXXXXsYV-&amp;export=download
    

    This link you can either open in your browser or access it programmatically by getting the body part of your message (filtering for Content-Type: text/html) and extracting the link e.g. with a Regex expression.