farid_92 farid_92 - 24 days ago 9
ASP.NET (C#) Question

How to send my Credentials securely using smtpClient with ASP.Net

I have a page in my website which users can send messages to website's admin.
I use the Email address which server gave to me to send the message to myself. I don't have problem in coding but the thing that I'm concerned about, is the credential that I have to send to server like this:

System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("email", "password");
mySmtpClient.Credentials = myCredential;


I am sure that this will send these information in clear text.
How I can secure this?
can this following code secure everything independently?

smtpClient.EnableSsl = true;


these are some information that my server gave to me. should I use them?

Proxy Settings Exchange Online https://webmail.myserver.com (Port 443)
Principal name Exchange Online: msstd: webmail.myserver.com
Proxy authentication settings: Basic Authentication Webmail: webmail.myserver.com


By the way is it secure to use my username and password directly on my aspx file?
I mean can anybody reach these information?

Answer

The code file will be in clear text but the connection between your webserver and SMTP server will be secure if you use SSL. .NET will handle this for you if you (as you did) specify EnableSsl.