In my MVC project, I need to send an HTML table as an email to a client.
I have an email function in the web API that I should name:
public class FunctionsController : ApiController
{
[HttpPost]
[Route("{controller}/email")]
public void SendEmail(string to, string from, string body, string subject, string bcc)
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "xxxx";
MailMessage mailMessage = new MailMessage();
mailMessage.IsBodyHtml = true;
mailMessage.Body = body;
mailMessage.Subject = subject;
mailMessage.From = new MailAddress(from);
mailMessage.To.Add(new MailAddress(to));
mailMessage.Bcc.Add(new MailAddress(bcc));
smtpClient.Send(mailMessage);
}
I am not sure how to do this.
This is my sendEmail javascript function in my MVC project (using Knockout):
self.sendEmail = function (to, from, body, subject, bcc) {
$.ajax({
url: "../API/functions/email",
type: "POST",
data: {
'to': to,
'from': from,
'body': body,
'subject': subject,
'bcc' : bcc
},
contentType: "application/json",
success: function (data) {
console.log(ko.toJSON(data));
}
});
}
How do I get POST data in a web API? Is javascript function correct?
Thanks in advance.
source
share