Sending email with signature using Gmail API

2019-06-15 14:08发布

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

标签: php gmail-api
2条回答
Bombasti
2楼-- · 2019-06-15 14:20

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.

查看更多
甜甜的少女心
3楼-- · 2019-06-15 14:28

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.

查看更多
登录 后发表回答