Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Email in ASP.NET

Status
Not open for further replies.

arbo80

Programmer
Jan 5, 2006
53
0
0
US
Hi all,

I have the following code to send an email from a web interface and it works fine. However, I want to know if it's possible to replace the email address specified in "Mail.From" by the default client email address. If yes, how do I do that?

SmtpMail.SmtpServer = "localhost";
MailMessage Mail = new MailMessage();
Mail.From = "yourname@company.com"; <-- would like default client email address here
Mail.To = "manager@company.com";
Mail.Subject = "New Project from " + lblUser.Text;
Mail.Body = "Hi," + "\n" + "A new project requested by " + lblUser.Text + " on " + lblDate.Text;
try
{
SmtpMail.Send(Mail);
}
catch (Exception ex)
{
Response.Write("Exception occured: " + ex);
}

thanks,
A.
 
not exactly sure what you are asking. Why not put the MailFrom value in the web.config, then you can read it from there. And changes are only necessay to the web.config if it needs to be changed?
 
Thanks for your feedback. The application that I created is a web form. Every time a user submits the form, the application will send an email to my manager. Thus, the "Mail From" should be the email address of the user.
 
you can use the config file to configure global default values for sending emails. server, port, from, credentials, delivery method.

if needed you can override them in code.

btw. sending emails is independent the GUI. all the webform does is collect user input and send it in a http request. the server code creates an email messeage, populates the values and sends the message (text file) using the specified delivery method.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top