Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email with signature using Gmail API

Tags:

php

gmail-api

I got the Gmail Rest API sending part working but the e-mail doesn't include the signature and in recipient's inbox the 'from' label is sender's user id not the name of the user.

This is in php.

    $mime = new Mail_mime();
    $mime->setFrom("ABCD");  //This doesn't work....
    $mime->setSubject('Testing');
    $mime->setTXTBody('This is a demo mail');
    $mime->addTo('[email protected]');
    $message_body = $mime->getMessage();
    $encodeMessage = base64url_encode($message_body);
    $message = new Google_Service_Gmail_Message();
    $message->setRaw($encodeMessage);
    $send = $service->users_messages->send('me', $message);

Is there anyway to include the signature and change the 'from'?

like image 457
Chaesung 'Jaesung' Yoon Avatar asked May 27 '15 02:05

Chaesung 'Jaesung' Yoon


2 Answers

The signature is not added by the API because it is a setting on the web client, not a global setting for the entire account. If you configure your Gmail account on Thunderbird, Outlook or another email client, Gmail will not add the signature either. You should think about Gmail in two separate ways:

  1. The web client interface, accessible at https://mail.google.com, which is just an email client like any other;
  2. Your inbox, the place where messages end up in, which is completely independent of the clients you use to access it.

In other words, this is an email client-dependent setting, and the only thing the clients do is add a bit of text to the text you write yourself, nothing else.

like image 180
borfast Avatar answered Sep 22 '22 20:09

borfast


I know this is old but you can retrieve via API the users signature.

https://developers.google.com/admin-sdk/email-settings/#manage_signature_settings

you can then append to your email that you are composing.

like image 26
PNC Avatar answered Sep 23 '22 20:09

PNC