Ir directamente para o fim dos matadados
Ir directamente para o início dos matadados
Está a ver a versão antiga (v. /pages/viewpage.action?pageId=93847554) desta página. ver diferenças ·  ver histórico de página

Using Gmail SMTP OAUTH

 


 

The Gmail IMAP and SMTP servers have been extended to support authorization via the industry-standard OAuth 2.0 protocol. Using OAUTH protocol, user can do authentication by Gmail Web OAuth instead of inputting user and password directly in application. This way is more secure, but a little bit complex.

https://developers.google.com/gmail/oauth_overview?hl=en

Create your project in Google Developers Console

To use Gmail OAUTH in your application, you must create a project in Google Developers Console at first.

  • Create your project at https://console.developers.google.com/projectcreate.

  • Select your project -> APIs & Services -> Dashboard -> Credentials;

  • Credentials -> Create Credentials -> OAuth client ID -> Web application or Other (Desktop Application). It depends on your application type.

  • Input a name for your application, input your current ASP/ASP.NET URL at Authorized redirect URIs, for example: http://localhost/gmailoauth/default.aspx. (Desktop Application doesn't require this step)

  • Click "Create", you will get your client id and client secret:

  • Enable Gmail API in "Library" -> Search "Gmail", then click "Gmail API" and enable it.

  • You should set detail information for your project at "OAuth consent screen" -> "Edit App".

  • Finally add "https://mail.google.com/" and "../auth/gmail.send" scopes at "OAuth consent screen" -> "Edit App" -> "Scopes for Google API".
    If you use Gmail RESTFul API to send email, please only use "../auth/gmail.send" scope to avoid your app throttled.

Scope Remarks

Gmail supports SMTP + OAUTH, but the API (https://mail.google.com/) scope is restricted API which requests to have full access to the Gmail account. Restricted API is throttled before your project is authenticated in by Google.

Using less restricted API (https://www.googleapis.com/auth/gmail.send) scope to send email via Gmail server is recommended.


Labels
  • Nenhum