Home » SQL Server

System.Net.Mail Configuration Of Web.Config

Hello everybody.

I am designing a web application for Leave Application of our faculties. There is a form in my website which represent the existing paper-back leave application form. Users(faculties) have to fill-up this web form and after validation an email will be send to the email address of our principal/hod. I hope that email address(s) will be provided to our group members. Now I want to know that what will be the required configuration of the web.config file? I found this blog ScottGu's Blog. Here the given configuration is :



      <smtp from="test@foo.com">

        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />




But I think this is not acceptable for my project as the smtp from="test@foo.com", userName, password are unknown to me. So what should I do. Am I able to understand my requirement to you? I need help.

Thank you.


4 Answers Found


Answer 1

you must provide the password  for sending the mails.

which smtp  host you are using for that

you need a password of test@foo.com mail  Id to provide in the web  config file  for sending the mails


Answer 2

for above mention configuration  u need to provide the SMTP Credential 


Answer 3

the other alternet is you can use the password  for test@foo.com and use the different configuration  for sending the mails. e.g



<add key ="Pass" value="password">


and use this code when sending the mail  

sm1.UseDefaultCredentials =


sm1.Credentials = basicAuthenticationInfo

sm1.Credentials =

New System.Net.NetworkCredential(ConfigurationManager.AppSettings("uid"), ConfigurationManager.AppSettings("password"))


Answer 4

Thank you very much.

Yes you are right.

Actually the scenario is that it is my college project  so I can not get any web-hosting facility. So what I did is that I created an email  account in GMail and have sent email to given email address(es). I have added the credentials of that newly created email address  into web.config.

Here it is :

				<network host="smtp.gmail.com" port="25" userName="my.email.address@gmail.com" password="mypassword"/>

And here is the C# script :

                Document PdfDocument = new Document(iTextSharp.text.PageSize.A4, 20, 20, 20, 20);
		PdfWriter.GetInstance(PdfDocument , new FileStream("filename" , FileMode.Create));
		PdfDocument.Add(new Paragraph("some data"));

		string file  = "filename";
		Attachment data = new Attachment(file , MediaTypeNames.Application.Octet);
		ContentDisposition disposition = data.ContentDisposition;
		disposition.CreationDate = System.IO.File.GetCreationTime(file);
		disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
		disposition.ReadDate = System.IO.File.GetLastAccessTime(file);

		MailMessage EMail = new MailMessage();
		EMail.From = new MailAddress("fromemailaddress");
		EMail.Subject = "Leave Application";
		EMail.Body = "Check out the attachment!";
		EMail.IsBodyHtml = true;

		SmtpClient smtp  = new SmtpClient();
		Smtp.EnableSsl = true;

		try {
		} catch (Exception) {

And it is working.

Can you please tell em how can I encrypt the password  written in web.config?

Thank you.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure