Web sitem için bir e-posta gönderme işlevi oluşturmaya çalışıyorum, ancak bir şekilde iç sunucu hataları bu şekilde almaya devam ettim, diğer yanıtlardan birkaç farklı yolu denedim, ancak bunların hiçbiri benim için çalışıyor. Burada ASP.NET smtp sunucusunu kullanarak gmail gönderme
benim ajax çağrısıdır:self.sendEmail = function() {
var data = { Email: self.Email() };
showAjaxLoader();
$.ajax({
type: 'POST',
url: 'api/Account/EMail',
data: JSON.stringify(data),
contentType: "application/json",
headers: getAuthHeader(tokenKey)
}).done(function (data) {
hideAjaxLoader();
}).success(function (data) {
console.log("success");
}).fail(showError);
}
ve burada bunun için kontrolör geçerli:
[AllowAnonymous]
[HttpPost]
[Route("Email")]
public async Task<HttpResponseMessage> Email(BindingModel model)
{
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("[email protected]", "password"),
EnableSsl = true
};
client.Send("[email protected]", model.Email, "test", "testbody");
return Request.CreateResponse<BindingModel>(HttpStatusCode.OK, model);
}
hatadır: "POST http://localhost:52116/api/Account/Email 500 (Dahili Sunucu Hatası)"
"Özel durum oluştu: System.dll dosyasındaki 'System.Net.Mail.SmtpException'"
istisna şöyledir: "Exception throw: System.dll dosyasında System.Net.Mail.SmtpException" – user3514453
İstisna ayrıntıyı bu şekilde yapabilirsiniz ... Yakala (Exception ex) {ex.ToString(); } –