ASP.NET ဝဘ်စာမျက်နှာများ - WebMail အကူအညီပေးသူ
WebMail Helper - များစွာသော အသုံးဝင်သော ASP.NET Web Helpers များထဲမှ တစ်ခု။
WebMail အရာဝတ္ထုဖြင့် သင်သည် ဝဘ်စာမျက်နှာမှ အီးမေးလ်များကို အလွယ်တကူ ပေးပို့နိုင်ပါသည်။
WebMail အကူအညီပေးသူ
WebMail Helper သည် SMTP (Simple Mail Transfer Protocol) ကို အသုံးပြု၍ ဝဘ်အပလီကေးရှင်းမှ အီးမေးလ်တစ်စောင် ပေးပို့ရန် လွယ်ကူစေသည်။
ဇာတ်လမ်း- အီးမေးလ်ပံ့ပိုးမှု
အီးမေးလ်အသုံးပြုမှုကို သရုပ်ပြရန်၊ ကျွန်ုပ်တို့သည် ပံ့ပိုးကူညီမှုအတွက် ထည့်သွင်းစာမျက်နှာတစ်ခုကို ဖန်တီးမည်ဖြစ်ပြီး၊ အသုံးပြုသူသည် စာမျက်နှာကို အခြားစာမျက်နှာသို့ တင်သွင်းခွင့်ပေးကာ ပံ့ပိုးမှုပြဿနာနှင့်ပတ်သက်၍ အီးမေးလ်တစ်စောင် ပေးပို့မည်ဖြစ်သည်။
ပထမဦးစွာ သင်၏ AppStart စာမျက်နှာကို တည်းဖြတ်ပါ။
အကယ်၍ သင်သည် ဤသင်ခန်းစာတွင် Demo အပလီကေးရှင်းကို တည်ဆောက်ထားပါက၊ သင့်တွင် _AppStart.cshtml ဟုခေါ်သော စာမျက်နှာတစ်ခု ရှိနှင့်ပြီးဖြစ်သည်-
_AppStart.cshtml
@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId",
"Email", true);
}
WebMail အကူအညီကို စတင်ရန်၊ သင်၏ AppStart စာမျက်နှာတွင် အောက်ပါ WebMail ဂုဏ်သတ္တိများကို ပေါင်းထည့်ပါ။
_AppStart.cshtml
@{
WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId",
"Email", true);
WebMail.SmtpServer = "smtp.example.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "[email protected]";
WebMail.Password = "password-goes-here";
WebMail.From = "[email protected]";
}
Properties များကို ရှင်းပြထားသည်
SmtpServer- အီးမေးလ်များပေးပို့ရန်အသုံးပြုမည့် SMTP ဆာဗာအမည်။
SmtpPort- SMTP ငွေပေးငွေယူ (အီးမေးလ်များ) ပေးပို့ရန် ဆာဗာမှ အသုံးပြုမည့် ဆိပ်ကမ်း။
EnableSsl- ဆာဗာသည် SSL (Secure Socket Layer) ကုဒ်ဝှက်ခြင်းကို အသုံးပြုရမည်ဆိုပါက မှန်ပါသည်။
အသုံးပြုသူအမည်- အီးမေးလ်ပေးပို့ရာတွင် အသုံးပြုသည့် SMTP အီးမေးလ်အကောင့်၏ အမည်။
စကားဝှက်- SMTP အီးမေးလ်အကောင့်၏ စကားဝှက်။
ထံမှ - လိပ်စာမှ ပေါ်လာမည့် အီးမေးလ် (အသုံးပြုသူအမည်နှင့် မကြာခဏ တူညီသည်)။
ဒုတိယ- အီးမေးလ်ထည့်သွင်းမှုစာမျက်နှာ ဖန်တီးပါ။
ထို့နောက် ထည့်သွင်းစာမျက်နှာတစ်ခုကို ဖန်တီးပြီး ၎င်းကို Email_Input ဟု အမည်ပေးလိုက်ပါ။
Email_Input.cshtml
<!DOCTYPE html>
<html>
<body>
<h1>Request for
Assistance</h1>
<form method="post" action="EmailSend.cshtml">
<label>Username:</label>
<input type="text" name="customerEmail" />
<label>Details about the problem:</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:"[email protected]", subject: "Help request from - " + customerEmail, body:
customerRequest );
}
catch (Exception ex )
{
<text>@ex</text>
}
}
WebMail Object ရည်ညွှန်းချက် - Properties
Properties | Description |
---|---|
SmtpServer | The name the SMTP server that will send the emails |
SmtpPort | The port the server will use to send SMTP emails |
EnableSsl | True, if the server should use SSL encryption |
UserName | The name of the SMTP account used to send the email |
Password | The password of the SMTP account |
From | The email to appear in the from address |
WebMail Object ရည်ညွှန်းချက် - နည်းလမ်းများ
Method | Description |
---|---|
Send() | Sends an email message to an SMTP server for delivery |
Send() method တွင် အောက်ပါ parameter များ ပါရှိသည်။
Parameter | Type | Description |
---|---|---|
to | String | The Email recipients (separated by semicolon) |
subject | String | The subject line |
body | String | The body of the message |
နှင့် အောက်ပါ ရွေးချယ်နိုင်သော ဘောင်များ-
Parameter | Type | Description |
---|---|---|
from | String | The email of the sender |
cc | String | The cc emails (separated by semicolon) |
filesToAttach | Collection | Filenames |
isBodyHtml | Boolean | True if the email body is in HTML |
additionalHeaders | Collection | Additional headers |
နည်းပညာဆိုင်ရာဒေတာ
Name | Value |
---|---|
Class | System.Web.Helpers.WebMail |
Namespace | System.Web.Helpers |
Assembly | System.Web.Helpers.dll |
WebMail Helper ကို စတင်ခြင်း
WebMail အကူအညီကို အသုံးပြုရန်၊ သင်သည် SMTP ဆာဗာသို့ ဝင်ရောက်ခွင့် လိုအပ်ပါသည်။ SMTP သည် အီးမေးလ်၏ "ထွက်ပေါက်" အစိတ်အပိုင်းဖြစ်သည်။ အကယ်၍ သင်သည် ဝဘ်အိမ်ရှင်ကို အသုံးပြုပါက၊ သင်သည် SMTP ဆာဗာအမည်ကို သိပြီးဖြစ်နိုင်သည်။ အကယ်၍ သင်သည် ကော်ပိုရိတ်ကွန်ရက်တွင် အလုပ်လုပ်ပါက၊ သင်၏ IT ဌာနသည် သင့်အား အမည်ပေးနိုင်ပါသည်။ သင်သည် အိမ်၌အလုပ်လုပ်နေပါက၊ သင်သည် သင်၏သာမန်အီးမေးလ်ဝန်ဆောင်မှုပေးသူကို အသုံးပြုနိုင်သည်။
အီးမေးလ်တစ်စောင်ပေးပို့ရန်အတွက် သင်လိုအပ်လိမ့်မည်-
- SMTP ဆာဗာအမည်
- ဆိပ်ကမ်းနံပါတ် (အများစုကတော့ 25)၊
- အီးမေးလ်အသုံးပြုသူအမည်
- အီးမေးလ် စကားဝှက်တစ်ခု
သင့်ဝဘ်၏ အမြစ်တွင် _AppStart.cshtml အမည်ရှိ စာမျက်နှာတစ်ခု ဖန်တီးပါ (သို့မဟုတ် စာမျက်နှာကို တည်းဖြတ်ပါ) ။
ဖိုင်အတွင်း အောက်ပါကုဒ်ကို ထည့်ပါ။
_AppStart.cshtml
@{
WebMail.SmtpServer = "smtp.example.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
WebMail.UserName = "[email protected]";
WebMail.Password = "password";
WebMail.From = "[email protected]"
}
ဝဘ်ဆိုက် (အက်ပ်လီကေးရှင်း) စတင်ချိန်တိုင်း အပေါ်ကကုဒ်က အလုပ်လုပ်ပါလိမ့်မယ်။ ၎င်းသည် သင်၏ WebMail Object ကို ကနဦးတန်ဖိုးများဖြင့် ကျွေးမွေးပါသည်။
ကျေးဇူးပြု၍ အစားထိုးပါ-
smtp.example.com အီးမေးလ်များကို ပေးပို့ရန်အတွက် အသုံးပြုမည့် SMTP ဆာဗာအမည်ဖြင့်
25 SMTP ငွေပေးငွေယူ (အီးမေးလ်များ) ပေးပို့ရန် ဆာဗာက အသုံးပြုမည့် ပို့တ်နံပါတ်ဖြင့်။
အကယ်၍ ဆာဗာသည် SSL (Secure Socket Layer) ကုဒ်ဝှက်ခြင်းကို အသုံးပြုသင့်ပါက true ဖြင့် false ။
အီးမေးလ်များပေးပို့ရန်အသုံးပြုသည့် SMTP အီးမေးလ်အကောင့်အမည်ဖြင့် [email protected]
SMTP အီးမေးလ်အကောင့်၏ စကားဝှက်ဖြင့် စကားဝှက် ။
john@example အနေဖြင့် လိပ်စာမှ ပေါ်လာမည့် အီးမေးလ်။
သင့် AppStart ဖိုင်တွင် WebMail အရာဝတ္ထုကို စတင်လုပ်ဆောင်ရန် မ လိုအပ် သော်လည်း WebMail.Send() နည်းလမ်းကို မခေါ်ဆိုမီ ဤဂုဏ်သတ္တိများကို သတ်မှတ်ရပါမည် ။