亚洲欧洲国产欧美一区精品,激情五月亚洲色五月,最新精品国偷自产在线婷婷,欧美婷婷丁香五月天社区

      考試首頁 | 考試用書 | 培訓課程 | 模擬考場 | 考試論壇  
        當前位置:編程開發(fā) > DotNET > ASP.Net > 文章內容
        

      ASP.NETWebPages教程:WebMail幫助器

       [ 2016年4月18日 ] 【

      WebMail 幫助器

      WebMail 幫助器使我們更容易從 web 應用程序中使用 SMTP 來發(fā)送電郵。

      腳本: Email 支持

      為了演示電子郵件的使用,我們將創(chuàng)建用于技術支持的輸入頁面,讓用戶向另一個頁面提交該頁面,然后發(fā)送一封有關支持問題的電子郵件。

      首先:編輯您的 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: 發(fā)送電郵所使用的 SMTP 服務器的名稱。

      SmtpPort: 發(fā)送 SMTP transactions (電郵) 所用的服務器端口。

      EnableSsl: True,如果服務器應該使用 SSL (Secure Socket Layer) 加密。

      UserName: 發(fā)送電郵所用的 SMTP email 賬戶的名稱。

      Password: SMTP 電郵賬戶的密碼。

      From: 出現在 from 欄中的電郵地址(通常與 UserName 相同)。

      第二:創(chuàng)建電郵輸入頁面

      然后創(chuàng)建輸入頁面,名為 Email_Input:

      Email_Input.cshtml

       
       
       
      

      Request for Assistance

      輸入頁面的作用是收集信息,然后把數據提交到一個能夠將信息作為郵件來發(fā)送的新頁面。

      第三:創(chuàng)建郵件發(fā)送頁面

      然后創(chuàng)建用于發(fā)送電郵的頁面,名為 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 )
      {
      @ex 
      }
      }
      

      將考試網添加到收藏夾 | 每次上網自動訪問考試網 | 復制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
      關于本站  網站聲明  廣告服務  聯系方式  站內導航  考試論壇
      Copyright © 2007-2013 中華考試網(Examw.com) All Rights Reserved