I'm trying to send an email to myself after someone has posted a question. Although I'm receiving an email, it isn't what I need: the from mailaddress is my own instead of the person who asked the question.
Is it possible to send a mail to yourself (I don't know the smtp host, username or password from the person who's asking the question).
I'll add some code in case you need it.
QuestionsController.cs
MailMessage msg = new MailMessage();
msg.From = new MailAddress(question.Author + "<" + question.MailAuthor + ">");
msg.To.Add("myGmailAddress");
msg.Subject = question.Title;
msg.Body = question.Message;
msg.Sender = new MailAddress(question.MailAuthor);
SmtpClient client = new SmtpClient();
client.Send(msg);
My code first didn't include msg.sender, but I tried it by adding a sender, but that also didn't help.
Web.config (outside the view folder)
<system.net>
<mailSettings>
<smtp from="myGmailAddress">
<network
host="smtp.gmail.com"
password="myPassword"
userName="myGmailAddress"
port="587"
enableSsl="true"
defaultCredentials="false" />
</smtp>
</mailSettings>
</system.net>
Also tried it without the from part and defaultCredentials="false".
When I debug the code I can see that the from in msg starts with my gmail address and changes when he gets past the msg.From part. But when I go to my mail I get this: