Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code to call web api after passing the Mailmessage class object

C#
MailMessage mail1 = new MailMessage();
mail1.Subject = "Testmail";
mail1.From = new MailAddress("test@gmail.com");
mail1.Body = "Hi, How are you?";
mail1.To.Add("test2@gmail.com");


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



Code in controller of web api to call

C#
public void SendMailMessage(MailMessage mailMessage)
        {
            _smtp = new SmtpClient("mail.gmail.com");
            _smtp.Send(mailMessage);
        }


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.
Posted
Comments
[no name] 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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900