1

I'm using Google's smtp servers to send email using oauth2. If I want to send with a different 'from' address, Google lets me specify one. If the from address is a verified send-as alias for the account, Google will use it in the email. If it's not a verified send-as alias, Google will silently (I think) swap the from address.

Is there any way I can tell via API whether Google will use the supplied email address? Maybe I'm asking if there's any way I can tell if an email is a send-as address for an account, but I'm open to other solutions for the bigger problem of knowing whether Google will honor the supplied from address.

Tim Haines
  • 1,496
  • 3
  • 14
  • 16

3 Answers3

1

If these are Google Apps accounts, you can use the Email Settings API to list send as addresses for the account.

If they're not Google Apps accounts or you prefer a more universal approach you could:

  1. Send an email from the address to the authenticated user directly via SMTP. Be sure to set a unique message ID before sending that you can track the message via.

  2. Connect to the user's mailbox via IMAP using OAuth authentication (same API scope as SMTP) and search for the sent message via message ID (rfc822msgid).

  3. Grab the headers of the message and look at the From: header. If it matches what you sent, the user is allowed to send as that address. If it's been reset to the authenticated user's primary address, the user is not allowed to send as that address.

Jay Lee
  • 13,415
  • 3
  • 28
  • 59
  • Jay, thanks. This is a good answer. They're Google Apps accounts, but the problem with the email-settings API is that it doesn't work with free accounts created before Dec 12. I think your alternate solution here is likely the best approach. – Tim Haines Mar 09 '14 at 05:21
0

You need to add your own SMTP server to send mail with that verified address.

SMTP configuration

JackPoint
  • 4,031
  • 1
  • 30
  • 42
  • That's one way I can make an address verified. But what I'm actually trying to do is determine if an email address has been verified as a 'send as' address or not. – Tim Haines Mar 05 '14 at 18:58
0

As far as I know, there isn't an API function for gmail to determine whether or not gmail will use your designated from address on outgoing emails that you send through your gmail account.

However, another way to check if gmail is using the from address that you supply may be to send a test message to an email address whereby incoming messages to this address are forwarded to a script which parses the headers of the incoming message and determines the from address of the message. If you are running an MTA on a Linux server with PHP or some other scripting language installed, cobbling this together is not hard to do. See http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/.

Another way to do this is to use a mail provider (such as Sendgrid) which offers a feature whereby incoming messages to an address at your domain are parsed and the headers are posted to a script on your web server (see http://sendgrid.com/docs/API_Reference/Webhooks/parse.html).

mti2935
  • 11,465
  • 3
  • 29
  • 33