Managing Aliases

Send-as aliases represent the email addresses an account can send mail from. Each account always has at least one alias to represent the primary email address of the account.

Send-as aliases correspond to the "Send mail as" feature in the web interface.

Aliases are also used to manage signatures for an account. Basic understanding of send-as aliases are required for you to be able to change email signatures. The above video shows you how to loop through send-as aliases and modify the signature for a user's primary email address.

For information on how to create, list, get, update, or delete aliases, see the SendAs reference.

Creating and verifying aliases

You must create aliases prior to use. In some cases, users must also verify ownership of the alias.

If Gmail requires user verification for an alias, the alias is returned with the status pending. A verification message is automatically sent to the target email address. The owner of the email address must complete the verification process before it can be used.

Aliases that do not require verification have a verification status of accepted.

Use the verify method to resend the verification request if needed.

SMTP settings

Aliases for external addresses should send mail through a remote SMTP mail sending agent (MSA). To configure the SMTP MSA for an alias, use the smtpMsa field to provide the connection details.

Managing signatures

You may also configure email signatures for each alias. For example, to set the signature for the user's primary address:



/* Class to demonstrate the use of Gmail Update Signature API */
public class UpdateSignature {
   * Update the gmail signature.
   * @return the updated signature id , {@code null} otherwise.
   * @throws IOException - if service account credentials file not found.
  public static String updateGmailSignature() throws IOException {
        /* Load pre-authorized user credentials from the environment.
           TODO(developer) - See for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);

    // Create the gmail API client
    Gmail service = new Gmail.Builder(new NetHttpTransport(),
        .setApplicationName("Gmail samples")

    try {
      SendAs primaryAlias = null;
      ListSendAsResponse aliases = service.users().settings().sendAs().list("me").execute();
      for (SendAs alias : aliases.getSendAs()) {
        if (alias.getIsPrimary()) {
          primaryAlias = alias;
      // Updating a new signature
      SendAs aliasSettings = new SendAs().setSignature("Automated Signature");
      SendAs result = service.users().settings().sendAs().patch(
      //Prints the updated signature
      System.out.println("Updated signature - " + result.getSignature());
      return result.getSignature();
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      GoogleJsonError error = e.getDetails();
      if (error.getCode() == 403) {
        System.err.println("Unable to update signature: " + e.getDetails());
      } else {
        throw e;
    return null;


gmail/snippet/settings snippets/
from __future__ import print_function

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

def update_signature():
    """Create and update signature in gmail.
    Returns:Draft object, including updated signature.

    Load pre-authorized user credentials from the environment.
    TODO(developer) - See
    for guides on implementing OAuth2 for the application.
    creds, _ = google.auth.default()

        # create gmail api client
        service = build('gmail', 'v1', credentials=creds)

        primary_alias = None

        # pylint: disable=E1101
        aliases = service.users().settings().sendAs().list(userId='me')\
        for alias in aliases.get('sendAs'):
            if alias.get('isPrimary'):
                primary_alias = alias

        send_as_configuration = {
            'displayName': primary_alias.get('sendAsEmail'),
            'signature': 'Automated Signature'

        # pylint: disable=E1101
        result = service.users().settings().sendAs() \
            .patch(userId='me', sendAsEmail=primary_alias.get('sendAsEmail'),
        print(F'Updated signature for: {result.get("displayName")}')

    except HttpError as error:
        print(F'An error occurred: {error}')
        result = None

    return result.get('signature')

if __name__ == '__main__':