Ich versuche, eine E-Mail-sendende Funktion für meine Website zu erstellen, aber irgendwie habe ich interne Serverfehler mit diesem erhalten, habe ich verschiedene Wege aus anderen Antworten versucht, aber keiner von ihnen funktioniert bei mir.ASP.NET Senden von Gmail mit SMTP-Server
hier ist mein Ajax-Aufruf:
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);
}
und hier ist die Steuerung dafür:
[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);
}
der Fehler ist: "POST http://localhost:52116/api/Account/Email 500 (Internal Server Error)"
"Ausnahme ausgelöst: 'System.Net.Mail.SmtpException' in System.dll"
die Ausnahme ist: "Ausnahme ausgelöst: 'System.Net.Mail.SmtpException' in System.dll" – user3514453
können Sie die Ausnahme Detail wie folgt trösten ... Catch (Exception ex) {ex.ToString(); } –