Home » SQL ServerRSS

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 :

<system.net>

    <mailSettings>

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

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

      </smtp>

    </mailSettings>

  </system.net>


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

<appSettings>

<addkey="uid"value="test@foo.com">

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

</appsetting>

and use this code when sending the mail  

sm1.UseDefaultCredentials =

False

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 :

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



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.Open();
		PdfDocument.Add(new Paragraph("some data"));
		PdfDocument.Close();

		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.To.Add("toemailaddress");
		EMail.From = new MailAddress("fromemailaddress");
		EMail.Subject = "Leave Application";
		EMail.Body = "Check out the attachment!";
		EMail.Attachments.Add(data);
		EMail.IsBodyHtml = true;

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

		try {
			Smtp.Send(EMail);
		} 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   |   Follow us on Twitter