使用MVC发送电子邮件3
问题描述:
我想使用MVC 3应用程序发送电子邮件。我在电子邮件地址数据库中有一个名为Reviewer的用户表。我想要的是当我使用复选框从视图中的表格中选择2-3个用户时,每个用户的电子邮件地址应自动插入反馈视图页面上的“文本框”,但它不起作用。它取自控制器的值Webmail.Send()
而不是反馈表单页面。有任何想法吗?使用MVC发送电子邮件3
[HttpPost]
public ActionResult Feedback(string email, string subject, string body)
{
try
{
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.EnableSsl = true;
WebMail.SmtpPort = 25;
WebMail.UserName = "[email protected]";
WebMail.Password = "*******123";
WebMail.From = "[email protected]";
WebMail.Send(
"[email protected]",
subject,
body,
email
);
return RedirectToAction("FeedbackSent");
}
catch (Exception ex)
{
ViewData.ModelState.AddModelError("_FORM", ex.ToString());
}
return View();
}
这是反馈的查看页面:
@using(Html.BeginForm()) {
<table>
<tr>
<td>Your e-mail:</td>
<td>@Html.TextBox("email")</td>
</tr>
<tr>
<td>Subject:</td>
<td>@Html.TextBox("subject")</td>
</tr>
<tr>
<td>Body:</td>
<td>@Html.TextArea("body")</td>
</tr>
</table>
<input type="submit" value="Send" />
}
答
你应该使用这样的:
WebMail.Send(
email,
subject,
body
);
或者你也可以消除行:
WebMail.From = "[email protected]";
而且使用:
WebMail.Send(
email,
subject,
body,
from: "[email protected]"
);
更多关于WebMail
类,什么参数WebMail.Send
都可以在这里找到:WebMail
Class on MSDN。
当你说它从控制器中获取价值时,你是什么意思? “from”电子邮件是“myemail @ gmail.com”,而不是表单中输入的内容? – 2012-04-01 13:52:30
我的意思是当我发送电子邮件时,它从“[email protected]”到“[email protected]”。但我想从“[email protected]”发送电子邮件给我从反馈页面上的复选框列表中选择的人员。 – Shaan 2012-04-01 14:06:57
我找不到目标电子邮件在哪里...您的控制器只有一个电子邮件作为参数,其他电子邮件是经过编码的。 – Romias 2012-04-01 18:20:54