ASP.NETウェブページ - WebMailヘルパー
- 前のページ WebPages グラフ
- 次のページ WebPages PHP
WebMailヘルパー - 複数の便利なASP.NETウェブヘルパーのうちの1つ。
WebMailヘルパー
WebMailヘルパーは、ウェブアプリケーションからSMTPを使用して電子メールを送信するのをより簡単にします。
スクリプト: Email サポート
技術サポートの使用を示すために、ユーザーが別のページにこのページを提出し、サポートに関する質問の電子メールを送信するための入力ページを作成します。
まず: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 = "support@example.com"; WebMail.Password = "password-goes-here"; WebMail.From = "john@example.com"; }
属性説明:
SmtpServer: 電子メールを送信するために使用されるSMTPサーバーの名前。
SmtpPort: SMTP取引(電子メール)を送信するために使用されるサーバーport。
EnableSsl: 服务器がSSL(Secure Socket Layer)暗号を使用する必要がある場合、Trueです。
UserName: SMTP電子メールアカウントの名前を使用して電子メールを送信するために使用されます。
Password: SMTP電子メールアカウントのパスワード。
From: from欄に表示される電子メールアドレス(通常はUserNameと同じです)。
第二:電子メール入力ページを作成
それから、入力ページを作成し、名前を Email_Input にします:
Email_Input.cshtml
<!DOCTYPE html> <html> <body> <h1>Request for Assistance</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>
入力ページの役割は情報を収集し、その情報をメールとして送信できる新しいページにデータを送信することです。
第3:メール送信ページの作成
次に、電子メールを送信するためのページを作成し、Email_Send という名前を付けます:
Email_Send.cshtml
@{ // 入力を読み込む var customerEmail = Request["customerEmail"]; var customerRequest = Request["customerRequest"]; try { // メール送信 WebMail.Send(to:"someone@example.com", subject: "Help request from - " + customerEmail, body: customerRequest ); } catch (Exception ex ) { <text>@ex</text> } }
ASP.NET Web Pages アプリケーションから電子メールを送信する詳細については、以下を参照してください:WebMail オブジェクトリファレンスマニュアル。
- 前のページ WebPages グラフ
- 次のページ WebPages PHP