ईमेल एक्शन लिंक बनाना

मोबाइल ऐप्स को कभी-कभी उपयोगकर्ताओं के साथ बातचीत करने और उन्हें ईमेल भेजकर कुछ कार्रवाई करने के लिए प्रेरित करने की आवश्यकता होती है।

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

यदि आप इसके बजाय अपने स्वयं के ईमेल टेम्प्लेट और अपनी स्वयं की ईमेल डिलीवरी सेवा का उपयोग करना चाहते हैं, तो यह पृष्ठ बताता है कि उपरोक्त प्रवाह के लिए प्रोग्रामेटिक रूप से एक्शन लिंक उत्पन्न करने के लिए फायरबेस एडमिन एसडीके का उपयोग कैसे करें, जिसे आप अपने उपयोगकर्ताओं को ईमेल में शामिल कर सकते हैं।

यह निम्नलिखित लाभों के साथ आता है:

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

ActionCodeSettings आरंभ करें

इससे पहले कि आप एक ईमेल कार्रवाई लिंक उत्पन्न कर सकें, आपको एक ActionCodeSettings उदाहरण प्रारंभ करने की आवश्यकता हो सकती है।

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

मोबाइल ऐप के माध्यम से खोले जाने वाले लिंक के लिए, आपको फायरबेस डायनेमिक लिंक को सक्षम करना होगा और अपने मोबाइल ऐप से इन लिंक का पता लगाने के लिए कुछ कार्य करने होंगे। ईमेल कार्रवाइयों के लिए फायरबेस डायनेमिक लिंक को कॉन्फ़िगर करने के तरीके के निर्देश देखें।

ActionCodeSettings उदाहरण प्रारंभ करने के लिए, निम्नलिखित डेटा प्रदान करें:

पैरामीटर प्रकार विवरण
url डोरी

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

  • जब लिंक को वेब एक्शन विजेट्स में संभाला जाता है, तो यह continueUrl क्वेरी पैरामीटर में डीप लिंक होता है।
  • जब लिंक को सीधे ऐप में प्रबंधित किया जाता है, तो यह डायनामिक लिंक के डीप लिंक में continueUrl क्वेरी पैरामीटर है।
iOS ({बंडलआईडी: स्ट्रिंग}|अपरिभाषित) बंडल आईडी सेट करता है। यदि यह ऐप्पल ऐप इंस्टॉल है तो यह लिंक को खोलने का प्रयास करेगा। ऐप को कंसोल में पंजीकृत होना आवश्यक है.
android ({पैकेजनाम: स्ट्रिंग, इंस्टॉलऐप:बूलियन|अपरिभाषित, न्यूनतम संस्करण: स्ट्रिंग|अपरिभाषित}|अपरिभाषित) एंड्रॉइड पैकेज का नाम सेट करता है। यदि एंड्रॉइड ऐप इंस्टॉल है तो यह लिंक को उसमें खोलने का प्रयास करेगा। यदि installApp पास हो गया है, तो यह निर्दिष्ट करता है कि एंड्रॉइड ऐप इंस्टॉल करना है या नहीं, यदि डिवाइस इसका समर्थन करता है और ऐप पहले से इंस्टॉल नहीं है। यदि यह फ़ील्ड packageName के बिना प्रदान की जाती है, तो एक त्रुटि उत्पन्न होती है जो बताती है कि packageName इस फ़ील्ड के साथ संयोजन में प्रदान किया जाना चाहिए। यदि minimumVersion निर्दिष्ट है, और ऐप का पुराना संस्करण इंस्टॉल किया गया है, तो उपयोगकर्ता को ऐप को अपग्रेड करने के लिए प्ले स्टोर पर ले जाया जाता है। एंड्रॉइड ऐप को कंसोल में पंजीकृत होना आवश्यक है।
handleCodeInApp (बूलियन|अपरिभाषित) क्या ईमेल कार्रवाई लिंक पहले मोबाइल ऐप या वेब लिंक में खोला जाएगा। डिफॉल्ट गलत है। सही पर सेट होने पर, एक्शन कोड लिंक को यूनिवर्सल लिंक या एंड्रॉइड ऐप लिंक के रूप में भेजा जाएगा और इंस्टॉल होने पर ऐप द्वारा खोला जाएगा। गलत स्थिति में, कोड पहले वेब विजेट पर भेजा जाएगा और फिर इंस्टॉल होने पर जारी रखने पर ऐप पर रीडायरेक्ट किया जाएगा।
dynamicLinkDomain (स्ट्रिंग|अपरिभाषित) यदि वर्तमान लिंक को फायरबेस डायनेमिक लिंक का उपयोग करके खोला जाना है तो डायनेमिक लिंक डोमेन (या उपडोमेन) को वर्तमान लिंक के लिए उपयोग करने के लिए सेट करता है। चूंकि प्रति प्रोजेक्ट कई डायनेमिक लिंक डोमेन कॉन्फ़िगर किए जा सकते हैं, यह फ़ील्ड स्पष्ट रूप से किसी एक को चुनने की क्षमता प्रदान करता है। यदि कोई उपलब्ध नहीं कराया गया है, तो सबसे पुराना डोमेन डिफ़ॉल्ट रूप से उपयोग किया जाता है।

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

नोड.जे.एस

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',
};

जावा

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();

अजगर

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",
}

सी#

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 ऑब्जेक्ट प्रदान करें। ऑपरेशन ईमेल एक्शन लिंक के साथ हल हो जाएगा। उपयोग किया गया ईमेल किसी मौजूदा उपयोगकर्ता का होना चाहिए.

नोड.जे.एस

// 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.
  });

जावा

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());
}

अजगर

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)

सी#

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 ऑब्जेक्ट प्रदान करें। ऑपरेशन ईमेल एक्शन लिंक के साथ हल हो जाएगा। उपयोग किया गया ईमेल किसी मौजूदा उपयोगकर्ता का होना चाहिए.

नोड.जे.एस

// 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.
  });

जावा

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());
}

अजगर

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)

सी#

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 ऑब्जेक्ट की आवश्यकता होती है। ऑपरेशन ईमेल एक्शन लिंक के साथ हल हो जाएगा।

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

नोड.जे.एस

// 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.
  });

जावा

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());
}

अजगर

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)

सी#

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);

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

ईमेल लिंक का उपयोग करके फायरबेस के साथ उपयोगकर्ताओं को प्रमाणित करने के बारे में और जानें। इससे उपयोगकर्ता द्वारा लिंक पर क्लिक करने और ऐप पर वापस रीडायरेक्ट होने के बाद साइन-इन पूरा करने के तरीके के बारे में जानकारी प्रदान करने में मदद मिलेगी।