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('a@a.com');
$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'?
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:
- The web client interface, accessible at https://mail.google.com, which is just an email client like any other;
- 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.
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.