उपनाम मैनेज करना

'इस रूप में भेजें' ऐसे ईमेल पते होते हैं जिनसे कोई खाता मेल भेज सकता है. हर खाते में हमेशा कम से कम एक उपनाम होता है, जो खाते के मुख्य ईमेल पते को दिखाता है.

'इस रूप में भेजें' सुविधा, वेब इंटरफ़ेस में "इस रूप में मेल भेजें" सुविधा से जुड़ी होती है.

उपनाम का इस्तेमाल, किसी खाते के हस्ताक्षर को मैनेज करने के लिए भी किया जाता है. आपके लिए ईमेल हस्ताक्षर बदलने में सक्षम होने के लिए इस रूप में भेजें उपनाम की बुनियादी जानकारी ज़रूरी है. ऊपर दिया गया वीडियो, ईमेल उपनाम भेजने की सुविधा का इस्तेमाल करने और किसी उपयोगकर्ता के मुख्य ईमेल पते के हस्ताक्षर में बदलाव करने का तरीका बताता है.

उपनाम बनाने, सूची बनाने, पाने, अपडेट करने या मिटाने के तरीके के बारे में जानने के लिए, SendAs रेफ़रंस देखें.

उपनाम बनाना और उनकी पुष्टि करना

इस्तेमाल करने से पहले आपको उपनाम बनाना होगा. कुछ मामलों में, उपयोगकर्ताओं को उपनाम के मालिकाना हक की पुष्टि भी करनी होगी.

अगर Gmail को किसी उपनाम के लिए उपयोगकर्ता की पुष्टि की ज़रूरत होती है, तो उपनाम को pending स्थिति के साथ लौटाया जाता है. टारगेट किए गए ईमेल पते पर, पुष्टि करने का एक मैसेज अपने-आप भेज दिया जाता है. ईमेल पते का इस्तेमाल करने से पहले, इसके मालिक को पुष्टि करने की प्रोसेस पूरी करनी होगी.

जिन उपनामों के लिए पुष्टि की ज़रूरत नहीं होती है उनकी पुष्टि की स्थिति accepted होती है.

अगर ज़रूरी हो, तो पुष्टि का अनुरोध फिर से भेजने के लिए, पुष्टि करें तरीके का इस्तेमाल करें.

एसएमटीपी सेटिंग

बाहरी पतों के उपनामों को किसी रिमोट एसएमटीपी मेल भेजने वाले एजेंट (एमएसए) के ज़रिए मेल भेजना चाहिए. किसी उपनाम के लिए एसएमटीपी एमएसए को कॉन्फ़िगर करने के लिए, smtpMsa फ़ील्ड का इस्तेमाल करके कनेक्शन की जानकारी दें.

हस्ताक्षर मैनेज करना

हर उपनाम के लिए ईमेल हस्ताक्षर भी कॉन्फ़िगर किए जा सकते हैं. उदाहरण के लिए, उपयोगकर्ता के मुख्य पते के लिए हस्ताक्षर सेट करने के लिए:

Java

gmail/snippets/src/main/java/UpdateSignature.java
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.gmail.Gmail;
import com.google.api.services.gmail.GmailScopes;
import com.google.api.services.gmail.model.ListSendAsResponse;
import com.google.api.services.gmail.model.SendAs;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;

/* 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 https://developers.google.com/identity for
            guides on implementing OAuth2 for your application. */
    GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
        .createScoped(GmailScopes.GMAIL_SETTINGS_BASIC);
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);

    // Create the gmail API client
    Gmail service = new Gmail.Builder(new NetHttpTransport(),
        GsonFactory.getDefaultInstance(),
        requestInitializer)
        .setApplicationName("Gmail samples")
        .build();

    try {
      SendAs primaryAlias = null;
      ListSendAsResponse aliases = service.users().settings().sendAs().list("me").execute();
      for (SendAs alias : aliases.getSendAs()) {
        if (alias.getIsPrimary()) {
          primaryAlias = alias;
          break;
        }
      }
      // Updating a new signature
      SendAs aliasSettings = new SendAs().setSignature("Automated Signature");
      SendAs result = service.users().settings().sendAs().patch(
              "me",
              primaryAlias.getSendAsEmail(),
              aliasSettings)
          .execute();
      //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;
  }
}

Python

gmail/snippet/settings स्निपेट/update_signature.py
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 https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()

  try:
    # create gmail api client
    service = build("gmail", "v1", credentials=creds)

    primary_alias = None

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

    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"),
            body=send_as_configuration,
        )
        .execute()
    )
    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__":
  update_signature()