एएसपी.एनटी.डब्ल्यू वेब पेज - वेबमेल सहायक

वेबमेल सहायक - अनेक उपयोगी एएसपी.एनटी.डब्ल्यू बचावों में से एक

वेबमेल सहायक

वेबमेल सहायक हमें वेब अनुप्रयोगों से सहजता से एसएमटीपी के जरिए ईमेल भेजने में मदद करता है।

स्क्रिप्ट: इमेल सहायता

इमेल के उपयोग का प्रदर्शन करने के लिए, हम तकनीकी सहायता के लिए इस्तेमाल करने वाला इनपुट पृष्ठ बनाएंगे, ताकि उपयोगकर्ता इस पृष्ठ को दूसरे पृष्ठ पर सबमिट कर सके और एक सहायता से संबंधित इमेल भेज सके.

पहला: अपना AppStart पृष्ठ संपादित करें

पहला: अपना AppStart पृष्ठ संपादित करें

_AppStart.cshtml

@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", 
true);
}

यदि आपने इस शिक्षा के DEMO अनुप्रयोग का निर्माण किया है, तो आपके साइट में _AppStart.cshtml पृष्ठ के नीचे दिए गए सामग्री होनी चाहिए:

_AppStart.cshtml

@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", 
true);
WebMail.SmtpServer = "smtp.example.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "support@example.com";
WebMail.Password = "password-goes-here";
WebMail.From = "john@example.com";
}

गुणों का व्याख्यान:

SmtpServer: इमेल भेजने के लिए इस्तेमाल किए जाने वाले SMTP सर्वर का नाम.

SmtpPort: SMTP transactions (इमेल) भेजने के लिए इस्तेमाल किए जाने वाले सर्वर पोर्ट.

EnableSsl: True, अगर सर्वर SSL (Secure Socket Layer) एन्क्रिप्शन का उपयोग करना चाहिए.

UserName: इमेल भेजने के लिए इस्तेमाल किए जाने वाले SMTP email खाते का नाम.

Password: SMTP इमेल खाते का पासवर्ड.

From: from स्तंभ में दिए गए इमेल पता (आमतौर पर UserName से मेल खाता है).

दूसरा: इमेल इनपुट पृष्ठ बनाएं

तब एक इनपुट पृष्ठ बनाएं, जिसे Email_Input कहा जाता है:

Email_Input.cshtml

<!DOCTYPE html> 
<html> 
<body> 
<h1>तत्वोद्धार के लिए अनुरोध</h1> 
<form method="post" action="EmailSend.cshtml"> 
<label>उपयोगकर्ता नाम:</label>
<input type="text name="customerEmail" />
<label>समस्या के बारे में विवरण:</label> 
<textarea name="customerRequest" cols="45" rows="4"></textarea> 
<p><input type="submit" value="Submit" /></p> 
</form> 
</body> 
</html>

इनपुट पृष्ठ का काम है जानकारी संग्रह करना और तब आंकड़े को एक नए पृष्ठ पर भेजना जो जानकारी को ईमेल के रूप में भेज सकता है。

तीसरा: ईमेल भेजन पृष्ठ बनाएं

तब ईमेल भेजने के लिए पृष्ठ बनाएं, जिसे Email_Send कहा जाए:

Email_Send.cshtml

@{ // Read input
var customerEmail = Request["customerEmail"];
var customerRequest = Request["customerRequest"];
try
{
// Send email 
WebMail.Send(to:"someone@example.com", 
subject: "Help request from - " + customerEmail, 
body: customerRequest ); 
}
catch (Exception ex )
{
<text>@ex</text> 
}
}

ASP.NET Web Pages अनुप्रयोग से ईमेल भेजने के बारे में अधिक जानने के लिए देखें:WebMail ऑब्जेक्ट संदर्भ दस्तावेज