드롭 다운 선택에 따라 특정 전자 메일 주소로 전자 메일을 리디렉션하고 싶습니다. 이메일을 [email protected]으로 보내거나 이메일 드롭 다운에서 선택한 정보가 [email protected]으로 이동해야합니다. 이미 양식을 만들었지 만 MVC actionResult 및 @Razor보기를 사용하여이 작업을 수행하는 방법을 잘 모릅니다MVC보기의 드롭 다운 선택을 기반으로 전용 전자 메일 주소로 전자 메일을 보내려면 어떻게해야합니까?
내보기
@model ETWServices.Models.ContactUs
@{
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant();
}
<div class="cards">
<div class="card">
<div id="contact-form" class="clearfix">
@Html.ValidationSummary(true)
@using (Html.BeginForm())
{
<h1>
@Resources.ResContact.Title
</h1>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Subject)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Subject)
@Html.ValidationMessageFor(model => model.Subject)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Message)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</div>
<p>
<div class="submit">
<input type="submit" value="@Resources.ResContact.Send" id="btnSubmit" />
</div>
</p>
}
</div>
</div>
</div>
저희에게 연락는 컨트롤러
,[HttpPost]
public ActionResult Contact(ContactUs contUs)
{
if (ModelState.IsValid)
{
try
{
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress(contUs.Email);
mailMsg.To.Add("[email protected]");
mailMsg.Subject = contUs.Subject;
mailMsg.Body = contUs.Message;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "gmailpassword");
smtp.EnableSsl = true;
smtp.Send(mailMsg);
ModelState.Clear();
}
catch (Exception ex)
{
ModelState.Clear();
ViewBag.Message = " Sorry we are facing Problem here ";
}
}
return View();
}
은 저희에게 연락 모델
public class ContactUs
{
[Display(Name = nameof(Resources.ResContact.Name), ResourceType = typeof(Resources.ResContact))]
[Required(ErrorMessageResourceType =typeof(Resources.ResContact),
ErrorMessageResourceName = nameof(Resources.ResContact.NameReq))]
[StringLength(20, MinimumLength = 5,ErrorMessageResourceType =typeof(Resources.ResContact),
ErrorMessageResourceName = "NameShort")]
public string Name { get; set; }
[Display(Name = "Email", ResourceType =typeof(Resources.ResContact))]
[Required(ErrorMessageResourceType = typeof(Resources.ResContact),
ErrorMessageResourceName = "Emailrequired")]
[RegularExpression("[email protected]+\\..+", ErrorMessageResourceType = typeof(Resources.ResContact),
ErrorMessageResourceName = "EmailWrong")]
public string Email { get; set; }
[Required(ErrorMessageResourceType =typeof(Resources.ResContact),
ErrorMessageResourceName ="subjectRequired")]
[Display(Name = "Subject", ResourceType = typeof(Resources.ResContact))]
public string Subject { get; set; }
[Required(ErrorMessageResourceType = typeof(Resources.ResContact),
ErrorMessageResourceName = "msgRequired")]
[Display(Name = "Message", ResourceType = typeof(Resources.ResContact))]
public string Message { get; set; }
}