我是 MVC 的初学者,必须实现在 MVC 应用程序中发送邮件的功能。
下面是我的代码。
看法 :
@using (@Html.BeginForm())
{
@Html.TextBoxFor(m => m.EmailID)
<input type="submit" name="name" value="SendMail" />
@{ Html.RenderAction("SendMail", "PagesController");
}
控制器代码:PagesController
[HttpPost]
public ActionResult SendMail(EmailModel model)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@abc.com");
msg.To.Add(model.EmailID);
msg.Subject = "Welcome To REBAR Mobile Showcase";
msg.Body = "Hi," + Environment.NewLine + @"Welcome to REBAR Mobile Showcase. Please click on the below link : https://ciouishowcase.accenture.com/mobile/m"
+ Environment.NewLine + "Regards," + Environment.NewLine + "CIO Design Agency";
msg.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("abc", "passwrod", "Dir");
client.Host = "email.abc.com";
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Send(msg);
return View();
}
型号:EmailModel
public class EmailModel
{
public string EmailID { get; set; }
}
我在这里有几个问题:
单击发送链接按钮时,我应该如何调用此方法。
我也想在文本框和发送邮件链接上应用样式。我应该如何使用这些类型的控件?
@Html.TextBoxFor(m => m.EmailID)
- 我是否遵循 MVC 标准?如果没有,在哪里。