In sending data to email, can anyone help me check if I made mistake anywhere....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssmeshack85
    New Member
    • Oct 2009
    • 9

    In sending data to email, can anyone help me check if I made mistake anywhere....

    Hai there,

    Check whether I configure it correctly...

    Code:
    myMsg.To.Add("some1@hotmail.com");
    myMsg.From = new MailAddress("admin@emailserver.com");
    smtp.Host = "mail.emailserver.com";
    NetworkCred.UserName = "admin@emailserver.com";
    And can explain me what is this 4 actually?

    Code:
    MailMessage myMsg = new MailMessage();
            myMsg.To.Add("some1@hotmail.com");
            //TODO: Armour plate this method 
            myMsg.From = new MailAddress("admin@emailserver.com");
            myMsg.Subject = "Subject";
            myMsg.Body = "Name : " + txtName.Text +
            "\n Designation : " + txtDesignation.Text +
            "\n Organisation : " + txtOrganisation.Text +
            "\n Contact Number : " + txtTel.Text +
            "\n Facsimile: " + txtFax.Text +
            "\n Email : " + txtEmail.Text +
            "\n Choosen Courses : " + txtChoosen.Text; ;
    
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "mail.emailserver.com";
            smtp.EnableSsl = false;
            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
            NetworkCred.UserName = "admin@emailserver.com";
            NetworkCred.Password = "password";
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            //smtp.Port = 587;
            smtp.Send(myMsg);       
            lblConfirm.Text = "Thank you for your enquiry. We will get back to you as soon as possible. Have a nice day.";
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I'm sorry you're going to have to explain what the problem is in more detail.
    The second chunk of code sends an email....

    -Frinny

    Comment

    • ssmeshack85
      New Member
      • Oct 2009
      • 9

      #3
      Hai Frinny,

      Actually I did not upload to server yet to test...
      While im trying to test in my pc, it shows error like this...

      Code:
      An attempt was made to access a socket in a way forbidden by its access permissions 202.190.202.17:25 
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
      
      Exception Details: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 202.190.202.17:25
      
      Source Error: 
      
      
      Line 50:         smtp.Credentials = NetworkCred;
      Line 51:         //smtp.Port = 587;
      Line 52:         smtp.Send(myMsg);
      Line 53:         lblConfirm.Text = "Thank you for your feedback/suggestion. We will get back to you as soon as possible. Have a nice day."; 
      Line 54:     }
       
      
      Source File: c:\Documents and Settings\VIHETHI\My Documents\Visual Studio 2008\VIHETHI_WEB\onlineReg.aspx.cs    Line: 52
      What should I do get it work whithout upload to server... Any configuration or setting should I do in my pc...

      And the chunk 2 is the full codes.... to show you what I have done...

      Chunk 1 is for wheter I key in email addresses and smt host correctly?

      Thanks Frinny for your reply,

      Meshack

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I've seen this error before. It had to do with the way that the network was configured, the port that I was trying to send the email on was blocked by the network that my application was residing in. I would recommend that you check all firewall and router settings to make sure that you can send an email on the port that you need to use to send emails.

        Comment

        • ssmeshack85
          New Member
          • Oct 2009
          • 9

          #5
          Thanks Frinny.
          I will check that.
          Thanks again.

          Comment

          Working...