Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i wrote this code to send mail it works perfectly but i detected something very dangerous, it sends mail to people even if i don't provide my PASSWORD, i ony put "" instead of password in creditentials and it works why ?

C#
SmtpServer.Credentials = new System.Net.NetworkCredential(txtEmailFrom, "");
SmtpClient SmtpServer = new SmtpClient("[DELETED].pk");
                var mail = new MailMessage();
                mail.From = new MailAddress(txtEmailFrom);

                string[] to = txtEmailTo.Split(';');
                foreach (string mailTo in to)
                {
                    mail.To.Add(mailTo);
                }

                string[] cc = txtCC.Split(';');
                foreach (string copyTo in cc) 
                {
                    MailAddress cCopy = new MailAddress(txtCC);
                    mail.CC.Add(copyTo);
                } 
                mail.Subject = txtSubject;
                mail.IsBodyHtml = true;
               // mail.CC = txtCC;
                string htmlBody;
                htmlBody = txtBody;
                mail.Body = txtBody;
                SmtpServer.Port = 25;
                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials = new System.Net.NetworkCredential(txtEmailFrom, "");
                SmtpServer.EnableSsl = false;
               
			
	
	     try {
                SmtpServer.Send(mail);
                ViewBag.Confirmation = "Daily Log Has Been Submitted";
                return View();
             }
         
         catch (Exception ex) 
             {
               ViewBag.Confirmation = ex.Message;
               return View();
  	         }
      }


[edit]Open email server address removed - OriginalGriff[/edit]
Posted
Updated 18-Feb-14 21:46pm
v2
Comments
Sergey Alexandrovich Kryukov 19-Feb-14 3:30am    
Did you configure this server, or somebody else? The answer is: you have this problem because the server was configured this way, or even has a bug (much less likely)...
—SA

1 solution

Because your Email server is configured to not require credentials.
This is a very poor idea - almost as poor as publishing the server address - and I would strongly recommend you get your admin to fix it ASAP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900