Click here to Skip to main content
15,919,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Now I have this in my controller :
[HttpPost]
       public ActionResult ContactForm(ContactModel model)
       {
           if (ModelState.IsValid)
           {

               System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage(model.Email,"websiteowner@mail.com", model.Name, model.Comments);
               MyMailMessage.IsBodyHtml = true;
               System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("websiteowner@mail.com", "Password");
               System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
               mailClient.EnableSsl = true;
               mailClient.UseDefaultCredentials = false;
               mailClient.Credentials = mailAuthentication;
               mailClient.Send(MyMailMessage);
               TempData["notice"] = "Thanks for your message, its sent scuessfuly.";
               return RedirectToAction("FeedbackPage", "Home");

           }
           return View();
       }

Issue is that when I receive mail, I can see the Users Name who has sent it I can see that it is sent from website owner to website owner, The User email is no where to be seen in the message recived.
When I debug I can see the User's mail in place of(model.Email) but it dont ppear in the recived message.
Posted
Comments
Raul Iloc 28-Mar-14 12:58pm    
So did you succeeded to receive your email, but you cannot see the email body?
Jahangir Khan 28-Mar-14 13:24pm    
Yes but I am not happy because its not working exectly as I want, I can see the subjectI mean the body, but I can not see that its comeing from a user, who has put in his email, I can see the display mail which should be users, an it says To and thats also mine, so you get my point

1 solution

I see two possible cases of errors:
1.If you succeeded to send and receive your email, maybe you are using the MailMessage constructor parameters in not proper order.

If you are storing in your model.Email the email message, note that it should be send as the last parameter, and on the 2nd position you have to put the email address of the sender!

See the next MSDN link for details.[^]

2.If you are not in the situation from the 1st point and you are sending the parameters in the right order, then you should check in debug model.Comments because its content will be sent as email body. Maybe this filed is not linked correctly in your view!?
 
Share this answer
 

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