MVC 3 Web Mail
2011-12-09 23:12
232 查看
搞了许久,在网上也看个很多代码!终于给我弄出来了!拿出来跟大家分享一下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApp.Models
{
public class MailTestModel
{
public string MailAddress { get; set; }
public string MailTitle { get; set; }
public string MailContent { get; set; }
}
}
这是model
@model MvcApp.Models.MailTestModel
@{
ViewBag.Title = "Index";
}
<h2>
Index</h2>
@using (Html.BeginForm())
{
<label>
邮件标题:</label>@Html.TextBoxFor(model => model.MailTitle)
<label>
要发送的邮件地址:</label> @Html.TextBoxFor(model => model.MailAddress)
<label>
邮件内容:</label>@Html.TextBoxFor(model => model.MailContent)
<input type="submit" value="提交" />
}
这个是view视图
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApp.Models
{
public class MailTestModel
{
public string MailAddress { get; set; }
public string MailTitle { get; set; }
public string MailContent { get; set; }
}
}
这是model
@model MvcApp.Models.MailTestModel
@{
ViewBag.Title = "Index";
}
<h2>
Index</h2>
@using (Html.BeginForm())
{
<label>
邮件标题:</label>@Html.TextBoxFor(model => model.MailTitle)
<label>
要发送的邮件地址:</label> @Html.TextBoxFor(model => model.MailAddress)
<label>
邮件内容:</label>@Html.TextBoxFor(model => model.MailContent)
<input type="submit" value="提交" />
}
这个是view视图
// // GET: /WebMailTest/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(MailTestModel test) { WebMail.SmtpServer = "smtp.163.com";//获取或设置要用于发送电子邮件的 SMTP 中继邮件服务器的名称。 WebMail.SmtpPort = 25;//发送端口 WebMail.EnableSsl = true;//是否启用 SSL GMAIL 需要 而其他都不需要 具体看你在邮箱中的配置 WebMail.UserName = "ludingcheng0923";//账号名 WebMail.From = "ludingcheng0923@163.com";//邮箱名 WebMail.Password = "******";//密码 WebMail.SmtpUseDefaultCredentials = true;//是否使用默认配置 try { // Send email WebMail.Send(to: test.MailAddress, subject: test.MailTitle, body: test.MailContent //,cc: "抄送" // ,filesToAttach: filesPaths // , isBodyHtml: true, //additionalHeaders:new string[] { "additionalHeaders1", "additionalHeaders2" } ); } catch (Exception e) { Response.Write(e.ToString()); } return View(); } }
相关文章推荐
- WEB三层架构与MVC
- Struts 2权威指南:基于WebWork核心的MVC开发
- MVC3学习:利用mvc3+ajax检测用户是否被注册
- 探寻ASP.NET MVC鲜为人知的奥秘(1):对LESS的支持
- 命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?)
- iOS个人整理05-应用程序的启动流程--视图控制器ViewController的加载过程--MVC架构
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- MVC WebApi 用户验证 (2)
- WEB三层架构与MVC
- MVC中使用RadioButtonFor
- ActionLink()与jquery更好地结合建造MVC网页:
- MVC Ajax Helper或jQuery异步方式加载部分视图
- Mvc
- Spring3 MVC请求参数获取的几种方法
- Idea SpringMVC+Spring+MyBatis+Maven调整
- JavaEE框架Bootstrap HTML5 jQuery SpringMVC maven mybatis
- ASP.NET MVC 随想录——探索ASP.NET Identity 身份验证和基于角色的授权,中级篇
- (转)(转)【译】Asp.net MVC 利用自定义RouteHandler来防止图片盗链
- ASP.NET MVC Controller激活系统详解:IoC的应用[上篇]