MVC实现邮件发送(包含附件)
2021-02-07 12:18
标签:end NPU root textbox alert string cdn result etc 首先创建一个Model类来存放数据, 然后创建Controller, 在对应的View中新建Index.cshtml, MVC实现邮件发送(包含附件) 标签:end NPU root textbox alert string cdn result etc 原文地址:https://www.cnblogs.com/jizhiqiliao/p/13093216.html public class MailModel
{
[Required(ErrorMessage = "Please enter the receiver")]
public string To { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
}
public class SendMailerController : Controller
{
// GET: SendMailer
public ActionResult Index()
{
return View();
}
///
@model Attach_a_file_from_wwwroot_to_Email.Models.MailModel
@{
ViewBag.Title = "Index";
}
script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">script>
script>
$(document).ready(function () {
if (‘@ViewBag.Message‘ == ‘Sent‘) {
alert(‘Mail has been sent successfully‘);
}
});
script>
h2>Indexh2>
fieldset>
legend>
Send Email
legend>
@using (@Html.BeginForm("Index", "SendMailer", FormMethod.Post, new { @id = "form1", @enctype = "multipart/form-data" }))
{
input type="submit" value="Send" />
table>
tr>
td>
To:
td>
td>
@Html.TextBoxFor(m => m.To)
@Html.ValidationMessageFor(m => m.To)
td>
tr>
tr>
td>
Subject:
td>
td>
@Html.TextBoxFor(m => m.Subject)
td>
tr>
tr>
td>
Attachment
td>
td>
input type="file" name="fileUploader" /> @*和HttpPostedFileBase一致*@
td>
tr>
tr>
td>
Body:
td>
td>
@Html.TextAreaFor(m => m.Body)
td>
tr>
table>
}
fieldset>