ASP.NET Web Sayfaları - WebMail Yardımcısı
- Önceki Sayfa WebPages Grafik
- Sonraki Sayfa WebPages PHP
WebMail Yardımcısı - Çok sayıda faydalı ASP.NET Web Yardımcılarından biri.
WebMail Yardımcısı
WebMail Yardımcısı, web uygulaması üzerinden SMTP kullanarak e-posta göndermeyi daha kolay hale getirir.
脚本: 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 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>Request for Assistance</h1> <form method="post" action="EmailSend.cshtml"> <label>Kullanıcı Adı:</label> <input type="text name="customerEmail" /> <label>Sorun hakkında ayrıntılar:</label> <textarea name="customerRequest" cols="45" rows="4"></textarea> <p><input type="submit" value="Gönder" /></p> </form> </body> </html>
Giriş sayfasının amacı, bilgileri toplamak ve ardından bilgileri e-posta olarak gönderilebilecek yeni bir sayfaya göndermektir.
Üçüncü: E-posta gönderme sayfası oluşturma
Ardından, e-posta göndermek için kullanılacak sayfa, Email_Send adında oluşturulur:
Email_Send.cshtml
@{ // Girdi oku var customerEmail = Request["customerEmail"]; var customerRequest = Request["customerRequest"]; try { // E-posta gönder WebMail.Send(to:"someone@example.com", subject: "Destek talebi - " + customerEmail, body: customerRequest ); } catch (Exception ex ) { <text>@ex</text> } }
ASP.NET Web Sayfaları uygulamasından e-posta göndermekle ilgili daha fazla bilgi için bkz.:WebMail nesnesi Referans Kılavuzu.
- Önceki Sayfa WebPages Grafik
- Sonraki Sayfa WebPages PHP