When sending emails via C# how do you get the current users email address to put in the mail.From.Add(fromAddress)??

Sep 24 2009 2:32 PM
 
string
toAddress = [email protected];
string subject = "Test Mail with attachment";
string body = "Mail with attachment";
 

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add(toAddress);
mail.Subject = subject;
mail.Body = body;

mail.Attachments.Add(new Attachment(strm, "Letter.tif", contentType.ToString()));
SmtpServer.EnableSsl =
false;
SmtpServer.Send(mail);


Above is what I have for the above code to send an email.  And it works fine, but how can you grab the current logged on users email address to put into the from field.  Right now I know you can hardcode it in, or as I have it now I put it in the app.config.  But you do not know who will use this application nor their email address to hard code it in.

 
 
<
system.net>
<
mailSettings>
<smtp from=[email protected]>
<
network host="xxx.xxx.msft" port="25" userName="kiosk" password="kiosk3417" />
</
smtp>
</
mailSettings>
</
system.net>
 

 
But I want to do is deploy an application with the email code in it and it automatically gets the current users email address and puts it into the "From" part of the email.  The recipient will always be the same so no need to set anything up for that.

Answers (4)