hi
i already created once class which sends the email using SMTP....code for that class is showing below....
protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient("localhost");
MailAddress toAddr = new MailAddress("Receiver's Email Add");
MailAddress fromAddr = new MailAddress("sender's Email Add");
MailMessage message = new System.Net.Mail.MailMessage(fromAddr,toAddr);
message.IsBodyHtml = true;
message.Subject="Test Mail";
message.Body = "<html><body><b>This is an </b> <font color=red>HTML Message</font></body></html> ";
client.Send(message);
}
this is working fine....but I want to store some information in App.config file such as (from, to, and localhost). Can anyone tell me how to do that with the code....App.config code as well as .cs file code which is using that information.
thanks in advance ,,,,,,,It will be Good for me to get this work ASAP....
This is very straight forward![]()
in code behind
protected void Page_Load(object sender, EventArgs e)
{
string x = System.Configuration.ConfigurationManager.AppSettings["foo"].ToString();
}
in your web.config under the configurations area...
<appSettings>
<add key="foo" value="bar" />
</appSettings>
Dont forget that in VS2005 you can also use the "ASP.NET Configuration" menu under the Website menu and add application settings![]()
HTH,
He
... thank you so much...its working as i wanted...but i have one question......while searching for this problem..I found that in some sites ..they were talking about <System.Net> in web.config/app.config file!!
do it has any relation with this problem....!!
if you know then can tou please tell me .....i want to know abt tht just as an curiosity ..
Thank you !!
Pari
I do not think that they are related. :)
Glad I could help.
System.Net.Mail reads SMTP configuration data out of the standard .NET configuration system (so for ASP.NET applications you'd configure this in your application's web.config file). Here is an example of how to configure it: <system.net> <mailSettings> <smtpfrom="test@.foo.com">
<networkhost="smtpserver1"port="25"userName="username"password="secret"defaultCredentials="true" />
</smtp> </mailSettings> </system.net>I would suggest you fist reading this on msdnhttp://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
and then this one :http://aspnet.4guysfromrolla.com/articles/072606-1.aspx
Hope my suggestion helps :)
This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
0 comments:
Post a Comment