Click here to Skip to main content
14,265,748 members
Rate this:
Please Sign up or sign in to vote.
See more:
Code to call web api after passing the Mailmessage class object

MailMessage mail1 = new MailMessage();
mail1.Subject = "Testmail";
mail1.From = new MailAddress("");
mail1.Body = "Hi, How are you?";

response = confClient.PostAsJsonAsync("api/Utility/SendMailMessage/0", mail1).Result;

Code in controller of web api to call

public void SendMailMessage(MailMessage mailMessage)
            _smtp = new SmtpClient("");

What I have tried:

I dont know is this because of inbuilt .Net class, I tried in other example passing a student class worked fine. Able to pass values when Namespace System.Web.Mail is used instead of System.Net.Mail for Mailmessage class. I dont want to use System.web.mail.
Manas_Kumar 19-Feb-16 0:17am
If another class is working then why are you not using a custom class and assign all the properties then pass it to web api.
swapsun 22-Feb-16 16:34pm
Thank you for your reply. Had to do the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100