2

I'm using Google oAuth2 to authenticate my client then sending emails on their behalf using Zend (v1.12) SMTP, all using PHP. My question is how do I include the client's default email signature (as set in their Gmail settings) on the outgoing mail created using Zend?

I have full access to the client's Gmail so hoping there is a way to get their HTML signature and then add it to my html email body. Something like this:

...    
    if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
        $client->setAccessToken($_SESSION['access_token']);
        $obj=json_decode($_SESSION["access_token"],true);
        $client_token=$obj['access_token'];

        require_once 'Zend/Mail/Transport/Smtp.php';
        require_once 'Zend/Mail.php';

        $email = 'ClientJohn@abcco.com';//uses gmail business app
        $token = $client_token;
        $initClientRequestEncoded = base64_encode("user={$email}\1auth=Bearer {$token}\1\1");
        $config = array('ssl' => 'ssl', 'port' => '465', 'auth' => 'oauth2', 'xoauth2_request' => $initClientRequestEncoded);
        $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
        $mail = new Zend_Mail();

        // Not real code: 
        $signature=$_GET['client HTML signature'];
        // 

        $mail->setBodyText('EMAIL_BODY'.$signature);
        $mail->setBodyHtml('<b>EMAIL</b>_BODY'.$signature);
        $mail->setFrom('ClientJohn@abcco.com', 'Client John');
        $mail->addTo('michaelt@test.com', 'Michael F');
        $mail->setSubject('EMAIL_SUBJECT');
        $mail->send($transport);    
    } else {
        $authUrl = $client->createAuthUrl();
    }
...

I've reviewed the Gmail rest API (https://developers.google.com/gmail/api/) which doesn't say anything about signatures.

I've searched the web and reviewed numerous questions on Stack Overflow like: How to send an email in C# with gmail template/signature but don't think this works as I'm not creating the signature, just want to get what the client already uses. This is promising, just not sure how to implement it into my code (as it's using codeigniter): How can add email signature in codeigniter? Most of the web searches are about the digital signature of the email. I'm looking for the actual HTML signature at the bottom of the email I create.

If there isn't a way to get it from Gmail I'm thinking I'll have to have each client send me an email, copy and paste their signature HTML string into a database, then will have to pull that HTML for every email based on the user...not ideal because if they change their signature they'll also have to tell me so I can update the DB.

Community
  • 1
  • 1
michaelf
  • 469
  • 6
  • 20

1 Answers1

3

The signature is a client specific setting that sadly cannot be retrieved, as said by borfast here: Sending email with signature using Gmail API

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 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.

With this in mind, it would probably be a good idea for you to let your users create a separate signature in your application that you use when they send mail.

Community
  • 1
  • 1
Tholle
  • 108,070
  • 19
  • 198
  • 189
  • Thanks. As you stated, and I found in a few more places, there currently isn't a way to get the user's signature. Google devs, add to feature request? Thanks again. – michaelf Jun 10 '15 at 16:42