Neb*_*ran 4 html c# asp.net-mvc mailkit asp.net-core
我在Web应用程序上使用MVC ASP.NET Core 1.1.2.我尝试使用MailKit 1.18.1.1创建联系表单.我通过电子邮件(gmail)发送联系表格信息.当我在本地构建网页时,一切都按预期工作.我第一次在本地运行程序,它给了我同样的错误,但我启用了我的邮件地址的安全设置,它开始工作.但是当我在网络上部署它时,即使我设置安全设置以启用安全性较低的应用程序,它也会给我一个这样的错误:
这是Home Controller中的SendMail方法:
public IActionResult SendMail(string name, string phone, string email, string msg)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress ("theemailaddress@gmail.com"));
message.To.Add(new MailboxAddress("theemailaddresswhichrecievestheinfo@gmail.com"));
message.Subject = name;
message.Body = new TextPart("html")
{
Text = "Kimden: " + name + "<br>" + "Mail adresi: " + email + "<br>" +
"Mesaj: " + msg + "<br>" + "Telefon: " + phone
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587);
client.Authenticate("theemailaddress@gmail.com", "thepassword(I am sure it's correct)");
client.Send(message);
client.Disconnect(false);
}
return View("Contact");
}
Run Code Online (Sandbox Code Playgroud)
这是我的表单的Contact.cshtml代码:
@using (Html.BeginForm("SendMail", "Home"))
{
<div class="contactForm">
<form action="" method="POST" role="form" class="form">
<div class="form-group">
<input name ="name" type="text" class="form-control" id="" placeholder="Ad?n">
</div>
<div class="form-group">
<input name ="email" type="email" class="form-control" id="" placeholder="Mail Adresin">
</div>
<div class="form-group">
<input name="phone" type="text" class="form-control" id="" placeholder="Telefonun">
</div>
<div class="form-group">
<textarea name="msg" class="form-control" id="" placeholder="Mesaj?n"></textarea>
</div>
<button type="submit" class="btn buttonCustomPrimary">Mesaj gönder</button>
</form>
</div>
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |