13

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'?

  • 1
    Where are you adding the signature and what format are you setting From to, exactly? ("Sample User"? "Sample User "? "sample@gmail.com"? – Nathan Tuggy May 27 '15 at 02:38
  • Ok, thank you for the information. I got the 'From' label working after changing it to like you mentioned. As for signature, I was expecting Gmail to do it's job for me, I didn't do anything for the signature part within the code..... Do I have to include the signature manually? even if it's already in Gmail settings? – Chaesung 'Jaesung' Yoon May 27 '15 at 03:46
  • 1
    Well, I know nothing about the GMail API, but I would be a little surprised if it added a sig itself. Check the docs to be sure; I was trying to tease out the necessary information for someone else to answer. – Nathan Tuggy May 27 '15 at 03:57
  • Hmmm, ok for now I just copy pasted the source code of google signature and included as HTMLBody and it seems to work as it is. So far it seems that's the only way...... – Chaesung 'Jaesung' Yoon May 27 '15 at 06:31

2 Answers2

9

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.

borfast
  • 2,194
  • 1
  • 15
  • 34
4

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.

PNC
  • 1,932
  • 19
  • 36