ईमेल कार्रवाई लिंक जनरेट किए जा रहे हैं

मोबाइल ऐप्लिकेशन को कभी-कभी उपयोगकर्ताओं से इंटरैक्ट करना पड़ सकता है और उन्हें ईमेल भेजकर कुछ कार्रवाइयां करने का प्रॉम्प्ट मिलता है.

Firebase क्लाइंट SDK टूल की मदद से, उपयोगकर्ताओं को ऐसे लिंक वाले ईमेल भेजने की सुविधा मिलती है जिन्हें वे पासवर्ड फिर से सेट करने, ईमेल पते की पुष्टि करने, और ईमेल से साइन इन करने के लिए इस्तेमाल कर सकते हैं. ये टेम्प्लेट-आधारित ईमेल Google की ओर से भेजे जाते हैं और उन्हें पसंद के मुताबिक बनाने की सीमित सुविधाएं दी जाती हैं.

अगर आपको इसके बजाय, अपने ईमेल टेंप्लेट और ईमेल डिलीवरी सेवा का इस्तेमाल करना है, तो इस पेज पर बताया गया है कि ऊपर दिए गए फ़्लो के लिए, प्रोग्राम के हिसाब से ऐक्शन लिंक जनरेट करने के लिए, Firebase एडमिन SDK का इस्तेमाल कैसे करें. इन लिंक को अपने उपयोगकर्ताओं को भेजे जाने वाले ईमेल में शामिल किया जा सकता है.

इससे ये फ़ायदे मिलते हैं:

  • ईमेल टेंप्लेट को पसंद के मुताबिक बनाएं. इसमें नई स्टाइल जोड़ने और पसंद के मुताबिक ब्रैंडिंग करने, शब्दों और लोगो को बदलने, उपयोगकर्ताओं को पूरे नाम की जगह उनके नाम से बुलाने जैसी सुविधाएं शामिल हैं.
  • कॉन्टेक्स्ट के हिसाब से अलग-अलग टेंप्लेट लागू करें. उदाहरण के लिए, अगर न्यूज़लेटर की सदस्यता लेने के लिए उपयोगकर्ता अपने ईमेल की पुष्टि कर रहा है, तो हो सकता है कि ईमेल के कॉन्टेंट में विषय की जानकारी देना ज़रूरी हो. दूसरा उदाहरण है ईमेल लिंक में साइन इन करना: एक स्थिति में यह एक ही उपयोगकर्ता के ज़रिए या किसी दूसरे उपयोगकर्ता के न्योता मिलने पर ट्रिगर हो सकता है. ईमेल में कॉन्टेक्स्ट शामिल करना ज़रूरी है.
  • कस्टमाइज़ किए गए ईमेल टेंप्लेट को स्थानीय भाषा में उपलब्ध कराएं.
  • एक सुरक्षित सर्वर एनवायरमेंट से लिंक जनरेट करने की सुविधा.
  • किसी मोबाइल ऐप्लिकेशन या ब्राउज़र के ज़रिए, लिंक को खोलने के तरीके को पसंद के मुताबिक बनाने की सुविधा, और किसी राज्य की अतिरिक्त जानकारी देने का तरीका वगैरह
  • ईमेल कार्रवाई लिंक बनाते समय, मोबाइल ऐप्लिकेशन फ़्लो के लिए इस्तेमाल किए जाने वाले डाइनैमिक लिंक डोमेन को पसंद के मुताबिक बनाने की सुविधा मिलती है. यहां तक कि कॉन्टेक्स्ट या मोबाइल ऐप्लिकेशन के आधार पर यह भी कि एक अलग डाइनैमिक लिंक डोमेन तय किया जा सकता है.

ActionCodeSettings शुरू करें

ईमेल पर कार्रवाई का लिंक जनरेट करने से पहले, आपको ActionCodeSettings इंस्टेंस शुरू करना पड़ सकता है.

ActionCodeSettings की मदद से, जारी रखने वाले यूआरएल के ज़रिए अतिरिक्त स्थिति को पास किया जा सकता है. यह यूआरएल उपयोगकर्ता के ईमेल लिंक पर क्लिक करने के बाद ऐक्सेस किया जा सकता है. इससे उपयोगकर्ता को कार्रवाई पूरी होने के बाद ऐप्लिकेशन पर वापस जाने की सुविधा भी मिलती है. इसके अलावा, आपके पास यह तय करने का भी विकल्प है कि ईमेल कार्रवाई का लिंक, इंस्टॉल होने पर सीधे मोबाइल ऐप्लिकेशन से मैनेज किया जाए या ब्राउज़र से.

मोबाइल ऐप्लिकेशन से खुलने वाले लिंक के लिए, आपको Firebase डाइनैमिक लिंक चालू करने होंगे. साथ ही, अपने मोबाइल ऐप्लिकेशन में इन लिंक का पता लगाने के लिए कुछ काम करने होंगे. ईमेल से जुड़ी कार्रवाइयों के लिए, Firebase डाइनैमिक लिंक को कॉन्फ़िगर करने के तरीके से जुड़े निर्देश देखें.

ActionCodeSettings इंस्टेंस शुरू करने के लिए, यह डेटा दें:

पैरामीटर टाइप जानकारी
url स्ट्रिंग

यह ऐसा लिंक (स्टेट या जारी रखें यूआरएल) सेट करता है जिसका अलग-अलग मतलब अलग-अलग होता है:

  • जब लिंक को वेब ऐक्शन विजेट में हैंडल किया जाता है, तो यह continueUrl क्वेरी पैरामीटर में मौजूद डीप लिंक होता है.
  • जब लिंक को सीधे ऐप्लिकेशन में हैंडल किया जाता है, तो यह डाइनैमिक लिंक के डीप लिंक में continueUrl क्वेरी पैरामीटर होता है.
iOS ({bundleId: string}|undefined) बंडल आईडी सेट करता है. ऐसा करने से, Apple के ऐप्लिकेशन में मौजूद लिंक को खोलने की कोशिश की जाएगी. हालांकि, इसके लिए ज़रूरी है कि वह ऐप्लिकेशन इंस्टॉल हो. ऐप्लिकेशन, Console में रजिस्टर होना चाहिए.
android ({packageName: string, installApp:बूलियन|undefined, MinimumVersion: string|undefined}|undefined) Android पैकेज का नाम सेट करता है. ऐसा करने से, इस लिंक को किसी Android ऐप्लिकेशन में खोलने की कोशिश की जाएगी. हालांकि, ऐसा तब ही होगा, जब Android ऐप्लिकेशन इंस्टॉल हो. अगर installApp को पास कर लिया जाता है, तो इससे यह तय होता है कि Android ऐप्लिकेशन को इंस्टॉल करना है या नहीं. ऐसा तब होता है, जब डिवाइस पर यह सुविधा काम करती है और ऐप्लिकेशन पहले से इंस्टॉल नहीं है. अगर इस फ़ील्ड को packageName के बिना दिया जाता है, तो एक गड़बड़ी दिखती है. इसमें यह बताया जाता है कि इस फ़ील्ड के साथ packageName भी दिया जाना चाहिए. अगर minimumVersion बताया गया है और ऐप्लिकेशन का पुराना वर्शन इंस्टॉल है, तो ऐप्लिकेशन को अपग्रेड करने के लिए उपयोगकर्ता को Play Store पर ले जाया जाता है. Android ऐप्लिकेशन को Console में रजिस्टर होना ज़रूरी है.
handleCodeInApp (बूलियन|अनिर्धारित) ईमेल कार्रवाई के लिंक को मोबाइल ऐप्लिकेशन या वेब लिंक में खोला जाएगा या नहीं. डिफ़ॉल्ट रूप से, यह वैल्यू 'गलत' पर सेट होती है. अगर नीति को 'सही है' पर सेट किया जाता है, तो ऐक्शन कोड के लिंक को यूनिवर्सल लिंक या Android ऐप्लिकेशन के लिंक के तौर पर भेजा जाएगा. अगर ऐप्लिकेशन इंस्टॉल हो, तो उसे ऐप्लिकेशन में खोला जाएगा. गलत मामले में, कोड को सबसे पहले वेब विजेट पर भेजा जाएगा. इसके बाद, अगर ऐप्लिकेशन इंस्टॉल हो, तो जारी रखने पर, उसे ऐप्लिकेशन पर रीडायरेक्ट किया जाएगा.
dynamicLinkDomain (स्ट्रिंग|अनिर्धारित) अगर मौजूदा लिंक को Firebase डाइनैमिक लिंक का इस्तेमाल करके खोला जाना है, तो यह डाइनैमिक लिंक डोमेन (या सबडोमेन) को मौजूदा लिंक के लिए इस्तेमाल करता है. हर प्रोजेक्ट में एक से ज़्यादा डाइनैमिक लिंक डोमेन कॉन्फ़िगर किए जा सकते हैं. इस फ़ील्ड की मदद से, किसी एक डोमेन को साफ़ तौर पर चुना जा सकता है. अगर कोई डोमेन नहीं दिया गया है, तो डिफ़ॉल्ट रूप से सबसे पुराने डोमेन का इस्तेमाल किया जाता है.

नीचे दिए गए उदाहरण में, ईमेल की पुष्टि करने वाले लिंक को भेजने का तरीका बताया गया है. यह लिंक, मोबाइल ऐप्लिकेशन में सबसे पहले Firebase डाइनैमिक लिंक (Apple ऐप्लिकेशन com.example.ios या Android ऐप्लिकेशन com.example.android) के तौर पर खुलेगा, जहां ऐप्लिकेशन पहले से इंस्टॉल न होने और कम से कम वर्शन 12 होने पर इंस्टॉल होगा. डीप लिंक में, जारी रखने वाले यूआरएल का पेलोड https://www.example.com/checkout?cartId=1234 शामिल होगा. इस्तेमाल किया गया डाइनैमिक लिंक डोमेन coolapp.page.link है. इसे Firebase डाइनैमिक लिंक के साथ इस्तेमाल करने के लिए कॉन्फ़िगर किया जाना चाहिए.

Node.js के लिए

const actionCodeSettings = {
  // URL you want to redirect back to. The domain (www.example.com) for
  // this URL must be whitelisted in the Firebase Console.
  url: 'https://www.example.com/checkout?cartId=1234',
  // This must be true for email link sign-in.
  handleCodeInApp: true,
  iOS: {
    bundleId: 'com.example.ios',
  },
  android: {
    packageName: 'com.example.android',
    installApp: true,
    minimumVersion: '12',
  },
  // FDL custom domain.
  dynamicLinkDomain: 'coolapp.page.link',
};

Java

ActionCodeSettings actionCodeSettings = ActionCodeSettings.builder()
    .setUrl("https://www.example.com/checkout?cartId=1234")
    .setHandleCodeInApp(true)
    .setIosBundleId("com.example.ios")
    .setAndroidPackageName("com.example.android")
    .setAndroidInstallApp(true)
    .setAndroidMinimumVersion("12")
    .setDynamicLinkDomain("coolapp.page.link")
    .build();

Python

action_code_settings = auth.ActionCodeSettings(
    url='https://www.example.com/checkout?cartId=1234',
    handle_code_in_app=True,
    ios_bundle_id='com.example.ios',
    android_package_name='com.example.android',
    android_install_app=True,
    android_minimum_version='12',
    dynamic_link_domain='coolapp.page.link',
)

शुरू करें

actionCodeSettings := &auth.ActionCodeSettings{
	URL:                   "https://www.example.com/checkout?cartId=1234",
	HandleCodeInApp:       true,
	IOSBundleID:           "com.example.ios",
	AndroidPackageName:    "com.example.android",
	AndroidInstallApp:     true,
	AndroidMinimumVersion: "12",
	DynamicLinkDomain:     "coolapp.page.link",
}

C#

var actionCodeSettings = new ActionCodeSettings()
{
    Url = "https://www.example.com/checkout?cartId=1234",
    HandleCodeInApp = true,
    IosBundleId = "com.example.ios",
    AndroidPackageName = "com.example.android",
    AndroidInstallApp = true,
    AndroidMinimumVersion = "12",
    DynamicLinkDomain = "coolapp.page.link",
};

ज़्यादा जानने के लिए, ईमेल से जुड़ी कार्रवाइयों में पास होने की स्थिति देखें.

पासवर्ड रीसेट करने का लिंक जनरेट करने के लिए, मौजूदा उपयोगकर्ता का ईमेल पता और ActionCodeSettings ऑब्जेक्ट उपलब्ध कराएं. हालांकि, ऐसा करना ज़रूरी नहीं है. कार्रवाई, ईमेल कार्रवाई के लिंक से हल हो जाएगी. इस्तेमाल किया गया ईमेल पता किसी मौजूदा उपयोगकर्ता का होना चाहिए.

Node.js के लिए

// Admin SDK API to generate the password reset link.
const userEmail = 'user@example.com';
getAuth()
  .generatePasswordResetLink(userEmail, actionCodeSettings)
  .then((link) => {
    // Construct password reset email template, embed the link and send
    // using custom SMTP server.
    return sendCustomPasswordResetEmail(userEmail, displayName, link);
  })
  .catch((error) => {
    // Some error occurred.
  });

Java

String email = "user@example.com";
try {
  String link = FirebaseAuth.getInstance().generatePasswordResetLink(
      email, actionCodeSettings);
  // Construct email verification template, embed the link and send
  // using custom SMTP server.
  sendCustomEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
  System.out.println("Error generating email link: " + e.getMessage());
}

Python

email = 'user@example.com'
link = auth.generate_password_reset_link(email, action_code_settings)
# Construct password reset email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)

शुरू करें

email := "user@example.com"
link, err := client.PasswordResetLinkWithSettings(ctx, email, actionCodeSettings)
if err != nil {
	log.Fatalf("error generating email link: %v\n", err)
}

// Construct password reset template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link)

C#

var email = "user@example.com";
var link = await FirebaseAuth.DefaultInstance.GeneratePasswordResetLinkAsync(
    email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
SendCustomEmail(email, displayName, link);

लिंक जनरेट होने के बाद, इसे कस्टम पासवर्ड रीसेट ईमेल में डाला जा सकता है और फिर कस्टम एसएमटीपी सर्वर का इस्तेमाल करके संबंधित उपयोगकर्ता को ईमेल किया जा सकता है.

अगर आप डिफ़ॉल्ट पासवर्ड रीसेट लैंडिंग पेज का इस्तेमाल नहीं कर रहे हैं और अपना खुद का कस्टम हैंडलर बना रहे हैं, तो कस्टम ईमेल कार्रवाई हैंडलर बनाना देखें.

ईमेल की पुष्टि करने वाला लिंक जनरेट करने के लिए, मौजूदा उपयोगकर्ता का ऐसा ईमेल पता दें जिसकी पुष्टि नहीं हुई है. साथ ही, एक वैकल्पिक ActionCodeSettings ऑब्जेक्ट भी दें. कार्रवाई, ईमेल कार्रवाई के लिंक से हल हो जाएगी. इस्तेमाल किया गया ईमेल पता किसी मौजूदा उपयोगकर्ता का होना चाहिए.

Node.js के लिए

// Admin SDK API to generate the email verification link.
const useremail = 'user@example.com';
getAuth()
  .generateEmailVerificationLink(useremail, actionCodeSettings)
  .then((link) => {
    // Construct email verification template, embed the link and send
    // using custom SMTP server.
    return sendCustomVerificationEmail(useremail, displayName, link);
  })
  .catch((error) => {
    // Some error occurred.
  });

Java

String email = "user@example.com";
try {
  String link = FirebaseAuth.getInstance().generateEmailVerificationLink(
      email, actionCodeSettings);
  // Construct email verification template, embed the link and send
  // using custom SMTP server.
  sendCustomEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
  System.out.println("Error generating email link: " + e.getMessage());
}

Python

email = 'user@example.com'
link = auth.generate_email_verification_link(email, action_code_settings)
# Construct email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)

शुरू करें

email := "user@example.com"
link, err := client.EmailVerificationLinkWithSettings(ctx, email, actionCodeSettings)
if err != nil {
	log.Fatalf("error generating email link: %v\n", err)
}

// Construct email verification template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link)

C#

var email = "user@example.com";
var link = await FirebaseAuth.DefaultInstance.GenerateEmailVerificationLinkAsync(
    email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
SendCustomEmail(email, displayName, link);

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

अगर ईमेल की पुष्टि करने के लिए डिफ़ॉल्ट लैंडिंग पेज इस्तेमाल नहीं किया जा रहा है और अपना कस्टम हैंडलर बनाया जा रहा है, तो कस्टम ईमेल ऐक्शन हैंडलर बनाना लेख पढ़ें.

ईमेल लिंक से साइन इन करने की सुविधा से उपयोगकर्ताओं की पुष्टि करने से पहले, आपको अपने Firebase प्रोजेक्ट के लिए ईमेल लिंक से साइन इन करने की सुविधा चालू करनी होगी.

साइन-इन करने का लिंक जनरेट करने के लिए, उपयोगकर्ता का ईमेल पता और ActionCodeSettings ऑब्जेक्ट दें. इस मामले में ActionCodeSettings ऑब्जेक्ट की ज़रूरत होती है. इससे हमें यह जानकारी मिलती है कि साइन इन पूरा करने के लिए, लिंक पर क्लिक करने के बाद उपयोगकर्ता को कहां वापस करना है. ईमेल कार्रवाई के लिंक पर कार्रवाई पूरी हो जाएगी.

पासवर्ड रीसेट और ईमेल से पुष्टि करने के उलट, इस्तेमाल किया जाने वाला ईमेल यह ज़रूरी नहीं है कि वह किसी मौजूदा उपयोगकर्ता से जुड़ा हो. इसकी वजह यह है कि इस कार्रवाई का इस्तेमाल ईमेल लिंक के ज़रिए आपके ऐप्लिकेशन में नए उपयोगकर्ताओं को साइन अप करने के लिए किया जा सकता है.

Node.js के लिए

// Admin SDK API to generate the sign in with email link.
const useremail = 'user@example.com';
getAuth()
  .generateSignInWithEmailLink(useremail, actionCodeSettings)
  .then((link) => {
    // Construct sign-in with email link template, embed the link and
    // send using custom SMTP server.
    return sendSignInEmail(useremail, displayName, link);
  })
  .catch((error) => {
    // Some error occurred.
  });

Java

String email = "user@example.com";
try {
  String link = FirebaseAuth.getInstance().generateSignInWithEmailLink(
      email, actionCodeSettings);
  // Construct email verification template, embed the link and send
  // using custom SMTP server.
  sendCustomEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
  System.out.println("Error generating email link: " + e.getMessage());
}

Python

email = 'user@example.com'
link = auth.generate_sign_in_with_email_link(email, action_code_settings)
# Construct email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)

शुरू करें

email := "user@example.com"
link, err := client.EmailSignInLink(ctx, email, actionCodeSettings)
if err != nil {
	log.Fatalf("error generating email link: %v\n", err)
}

// Construct sign-in with email link template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link)

C#

var email = "user@example.com";
var link = await FirebaseAuth.DefaultInstance.GenerateSignInWithEmailLinkAsync(
    email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
SendCustomEmail(email, displayName, link);

लिंक जनरेट होने के बाद, उसे पसंद के मुताबिक साइन-इन ईमेल में डाला जा सकता है और फिर कस्टम एसएमटीपी सर्वर का इस्तेमाल करके संबंधित उपयोगकर्ता को ईमेल किया जा सकता है.

ईमेल लिंक का इस्तेमाल करके, Firebase की मदद से उपयोगकर्ताओं की पुष्टि करने के बारे में ज़्यादा जानें. इससे, उपयोगकर्ता को लिंक पर क्लिक करने और ऐप्लिकेशन पर वापस रीडायरेक्ट होने के बाद, साइन-इन करने की प्रोसेस पूरी करने के तरीके की जानकारी देने में मदद मिलेगी.