This should be simple, but there is something I'm not getting. The user fills out info and the btnClick does the code.
I would think the msgToAdd would be who the e-mail is going to. (Testing as my email.)
And that the msgFromAdd would be who the message is from, which is input by the person browsing. (Testing as my wife's email.)
Then the credentials I put in my email/password. (Which in reality, anything "mine" would be x company. So I would need to code in the company email password? :-/)
Anyway, I successfully send email to my address, but it says it's coming from my address and I need it to come from whatever address the user input.
I've searched everywhere, but all the code is the same and it makes no sense to me. Thanks.
SmtpClient smtpClient = new SmtpClient();
MailMessage mailMsg = new MailMessage();
MailAddress msgToAdd = new MailAddress("myemail@gmail.com");
MailAddress msgFromAdd = new MailAddress(tbxEmailAdd.Text);
mailMsg.To.Add(msgToAdd);
mailMsg.From = msgFromAdd;
mailMsg.Subject = ddlEmail.SelectedValue;
mailMsg.IsBodyHtml = true;
mailMsg.Body = tbxEmail.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "mypassword");
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Send(mailMsg);
So even with the overkill below, it still doesn't show the real sender's address.
MailAddress msgFromAdd = new MailAddress(tbxEmailAdd.Text);
mailMsg.From = msgFromAdd;
mailMsg.ReplyToList.Add(msgFromAdd);
mailMsg.ReplyTo = msgFromAdd;
mailMsg.Sender = msgFromAdd;
Also, the following DOES make the name show up. Still no email address though!
MailAddress msgFromAdd = new MailAddress(tbxEmailAdd.Text, "NAME");
I'm seriously losing it.