WebMail 幫助器使我們更容易從 web 應(yīng)用程序中使用 SMTP 來(lái)發(fā)送電郵。
為了演示電子郵件的使用,我們將創(chuàng)建用于技術(shù)支持的輸入頁(yè)面,讓用戶(hù)向另一個(gè)頁(yè)面提交該頁(yè)面,然后發(fā)送一封有關(guān)支持問(wèn)題的電子郵件。
如果您曾構(gòu)建過(guò)本教程中的 DEMO 應(yīng)用程序,那么站點(diǎn)中應(yīng)該存在擁有如下內(nèi)容的 _AppStart.cshtml 頁(yè)面:
@{ WebSecurity.InitializeDatabaseConnection("Users", "UserProfile", "UserId", "Email", true); }
如需初始化 WebMail 幫助器,請(qǐng)向您的 AppStart 頁(yè)面添加以下 WebMail 屬性:
@{ 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 服務(wù)器的名稱(chēng)。
SmtpPort: 發(fā)送 SMTP transactions (電郵) 所用的服務(wù)器端口。
EnableSsl: True,如果服務(wù)器應(yīng)該使用 SSL (Secure Socket Layer) 加密。
UserName: 發(fā)送電郵所用的 SMTP email 賬戶(hù)的名稱(chēng)。
Password: SMTP 電郵賬戶(hù)的密碼。
From: 出現(xiàn)在 from 欄中的電郵地址(通常與 UserName 相同)。
然后創(chuàng)建輸入頁(yè)面,名為 Email_Input:
Request for Assistance
輸入頁(yè)面的作用是收集信息,然后把數(shù)據(jù)提交到一個(gè)能夠?qū)⑿畔⒆鳛猷]件來(lái)發(fā)送的新頁(yè)面。
然后創(chuàng)建用于發(fā)送電郵的頁(yè)面,名為 Email_Send:
@{ // 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 } }
2015職稱(chēng)計(jì)算機(jī)考試書(shū)PowerPoint2007中 .. 定價(jià):¥45 優(yōu)惠價(jià):¥42 更多書(shū)籍 | |
2015年全國(guó)職稱(chēng)計(jì)算機(jī)考試教材(2007模 .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書(shū)籍 |