Email Support section with the users address as "From address"
I need to implement a “email support” section in our application. So email “To” address will be admin@mydomain.com” and from address will be the email address of the end user.(The end users email address may be on the same domain or another domain like user@mydomain.com or user@gmail.com).
In the application I am authenticated the email using admins account details (username and password)
System.Net.NetworkCredential("admin@mydomain.com", adminpassword);
Also I am using host address as “mail.mydomain.com” Issue is I am getting the following error:
“Mailbox unavailable. The server response was: From address must match authenticated address” error message.
Is it possible to send an email with the correct sender email address(users from address)
My code sample is
message.To.Add(“admin@mydomain.com”);
message.From = new MailAddress(“test@gmail.com”);
message.IsBodyHtml = true;
message.BodyEncoding = Encoding.UTF8;
var smtp = new SmtpClient("mail.mydomain.com");
smtp.Credentials = new System.Net.NetworkCredential(admin@mydomain.com, adminpassword);
smtp.EnableSsl = false;
object usrtkn = message;
smtp.Send(message);
In general the From address shouldn't be the user themselves, it should be an internal system address. This is mainly because the user isn't actually sending the email, the application is . In the email itself you can specify which user sent it (and what their email address is). You can perhaps even specify the user's email address in the ReplyTo field of the message.
But the message you're getting from the SMTP server pretty much says it all. If the message is "from" that user then the SMTP server refuses it because it's sensitive to authentication and origination of emails. To the SMTP server (to any SMTP server I would imagine) it looks like you're trying to spoof messages.
You cannot do what you are doing, because the SMTP server is not allowing you to "impersonate" the user's email address for sending to the system. And thank goodness this is the case or else people would be spamming/spoofing the heck out of everyone under someone else's name.
Why are you trying to have it appear that the user is sending an email to the application? Why not just have a support section of your application where users can "submit" requests for support to the system and then if you want to send emails out to the users, then your scenario will work, but just in reverse (where the system is the From
address and the user is the To
address).
上一篇: 防止反自动化的最佳注册方式