I have web site set up that has some forms authentication through LDAP. I’m sending an email when the currently logged in user clicks a button, however the email is being sent from my address, and not the user. This creates a bit of confusion.
What I want to do is send emails using the logged users account without having them enter their user information again.
I basically want to do this:
MailMessage message = new MailMessage();
message.From = new MailAddress(User.GetIdentity);
message.Subject = Subject;
message.Body = body;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("address.qweqwe", 25);
client.Credentials = new System.Net.NetworkCredential(User.Identity);
client.Send(message);
Getting the users email isn’t a big deal, I’ve already got methods for that, but I’m not sure how I should go about getting their credentials. They’ve already logged on to access the page, and I know they have an LDAP email.
Is there any way to do this without forcing the user to log in again just to send the email?
If your SMTP server requires Credentials, I can see 2 solutions.
Ask the user through the page from their Network Credential (username/password)
Setup an account that has right to relay on behalf of all users. This would allow you to set a single account for the SMTP server. Then, every time you send an email all you would do is change the MailMessage.From property.