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

मोबाइल ऐप्लिकेशन को कभी-कभी लोगों से इंटरैक्ट करना होगा. साथ ही, उन्हें कुछ कार्रवाइयों को पूरा करने में मदद मिलती है.

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

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

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

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

ActionCodeSettings शुरू करें

ईमेल कार्रवाई का लिंक जनरेट करने से पहले, आपको ActionCodeSettings इंस्टेंस.

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

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

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

पैरामीटर टाइप ब्यौरा
url स्ट्रिंग

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

  • जब लिंक को वेब ऐक्शन विजेट में हैंडल किया जाता है, तो यह continueUrl क्वेरी पैरामीटर में लिंक किया गया है.
  • जब लिंक को सीधे ऐप्लिकेशन में हैंडल किया जाता है, तो यह इसके डीप लिंक में continueUrl क्वेरी पैरामीटर है डाइनैमिक लिंक.
iOS ({bundleId: string}|undefined) बंडल आईडी सेट करता है. ऐसा करने से, Apple ऐप्लिकेशन में लिंक खुल जाएगा, तो तो यह इंस्टॉल हो जाता है. ऐप्लिकेशन, Console में रजिस्टर होना चाहिए.
android ({packageName: स्ट्रिंग, installApp:बूलियन|undefined, न्यूनतम वर्शन: स्ट्रिंग|undefined}|undefined) 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);

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

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

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

साइन-इन करने का लिंक जनरेट करने के लिए, उपयोगकर्ता का ईमेल पता और 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 की मदद से उपयोगकर्ताओं की पुष्टि करना. इससे उपयोगकर्ता को साइन-इन करने की प्रोसेस पूरी करने के तरीके के बारे में जानकारी मिलेगी लिंक पर क्लिक करने के बाद, उसे वापस ऐप्लिकेशन पर रीडायरेक्ट कर दिया जाता है.