locked
ERROR: An attempt was made to access a socket in a way forbidden by its access permissions

    Question

  • An attempt was made to access a socket in a way forbidden

    by its access permissions xxx.xxx.xxx.xxx:587

    I got this error while trying to send Mail using GMail SMTP Server with my credentials..

    Can any1 tell me what the cause of the problem ?

    It's a very Simple console application to send mail..


    Contact["name"] = "Vin.k.s";


    • Edited by ViN.k.S Tuesday, August 28, 2012 8:24 AM error prefix
    Monday, August 27, 2012 12:10 PM

Answers

  • This statment is what is causing the error

    SmtpClient SmtpServer = new SmtpClient(mv.SmtpServer);

    It doesn't like the IP and port combined like this xxx.xxx.xxx.xxx:587

    Instead use format below with IP a string and port a number.

    SmtpClient SmtpServer = new SmtpClient("xxx.xxx.xxx.xxx",587);



    jdweng

    • Marked as answer by ViN.k.S Tuesday, August 28, 2012 10:03 AM
    • Unmarked as answer by ViN.k.S Tuesday, August 28, 2012 10:03 AM
    • Marked as answer by ViN.k.S Thursday, August 30, 2012 7:30 AM
    Tuesday, August 28, 2012 8:40 AM
  • Ok it's DONE..

    because of windows7 security i was unable to open a socket to send a E-Mail..

    I asked our Admin for priviledge.. and it worked..


    Contact["name"] = "Vin.k.s"; If it helps, Mark as answer to help others..

    • Marked as answer by ViN.k.S Thursday, August 30, 2012 7:34 AM
    Thursday, August 30, 2012 7:34 AM
  • Sure here you are..

    the Generic exception was "Sending Failed" The screenshot here is of "InnerException".

    An attempt was made to acces a socket in way forbidden by it's acces permissions..

    I executed this program from my office.. is it Admin Priviledge/Firewall issue ??


    Contact["name"] = "Vin.k.s"; If it helps, Mark as answer to help others..


    • Edited by ViN.k.S Tuesday, August 28, 2012 8:23 AM innerexception
    • Marked as answer by ViN.k.S Thursday, October 04, 2012 7:24 AM
    Tuesday, August 28, 2012 7:48 AM

All replies

  • There are two way of using credientals

    1) Is to create credentials with user and password.  The credentials and the email "from address" must be the same for this to work.

    2) You can use the credentials setup on the PC in the Contrl panel mail utility.  This is like using a POP account in outlook.

    See sample code below

                SmtpClient myclient = new SmtpClient();

                myclient.UseDefaultCredentials = true;  //use default account in control panel
                myclient.Credentials = new System.Net.NetworkCredential("username", "user password");


                myclient.DeliveryMethod = SmtpDeliveryMethod.Network;


    jdweng

    Monday, August 27, 2012 1:19 PM
  • Can you show us the whole exception informatoin, that is with the stack trace too. (e.g. $exception.ToString() )


    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, please vote and/or mark the question answered. Available for contract programming.

    Monday, August 27, 2012 11:12 PM
  • Sure here you are..

    the Generic exception was "Sending Failed" The screenshot here is of "InnerException".

    An attempt was made to acces a socket in way forbidden by it's acces permissions..

    I executed this program from my office.. is it Admin Priviledge/Firewall issue ??


    Contact["name"] = "Vin.k.s"; If it helps, Mark as answer to help others..


    • Edited by ViN.k.S Tuesday, August 28, 2012 8:23 AM innerexception
    • Marked as answer by ViN.k.S Thursday, October 04, 2012 7:24 AM
    Tuesday, August 28, 2012 7:48 AM
  • i created a Struct like this..

    public struct MailArgs
            {
                public string MailFron, MailTo, UserName, Password, SmtpServer;
                public int ServerPort;// = 587;
                public bool SSL, IsHtml;// = true;
                public string MailSubject, MailBody;
                public MailPriority Priority;
    
            }

    and passed it to the SendMail Function..inside it i am getting all these values..

    the function is something like..

    try
                {
                    MailMessage smail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient(mv.SmtpServer);
                    smail.From = new MailAddress(mv.MailFron);
                    smail.To.Add(mv.MailTo);
                    smail.Subject = mv.MailSubject;
                    smail.Body = mv.MailBody;
                    smail.IsBodyHtml = mv.IsHtml;
                    SmtpServer.Port = mv.ServerPort; //587
                    SmtpServer.Credentials = new NetworkCredential(mv.UserName, mv.Password);
                    //SmtpServer.EnableSsl = mv.SSL; // true
                    SmtpServer.Send(smail);
                    //MessageBox.Show("mail Send");
                    return true;


    Contact["name"] = "Vin.k.s"; If it helps, Mark as answer to help others..

    Tuesday, August 28, 2012 8:20 AM
  • This statment is what is causing the error

    SmtpClient SmtpServer = new SmtpClient(mv.SmtpServer);

    It doesn't like the IP and port combined like this xxx.xxx.xxx.xxx:587

    Instead use format below with IP a string and port a number.

    SmtpClient SmtpServer = new SmtpClient("xxx.xxx.xxx.xxx",587);



    jdweng

    • Marked as answer by ViN.k.S Tuesday, August 28, 2012 10:03 AM
    • Unmarked as answer by ViN.k.S Tuesday, August 28, 2012 10:03 AM
    • Marked as answer by ViN.k.S Thursday, August 30, 2012 7:30 AM
    Tuesday, August 28, 2012 8:40 AM
  • Thanks a lot..

    i missed myclient.DeliveryMethod = SmtpDeliveryMethod.Network; SmtpClient also(SmtpServer,port);

    But the actually problem was i ran this code on Windows7 in my office PC.. And i don't have priviledges to open a socket connection... :( 

    that was the problem finally i executed this code on Server(admin priviledge) and it worked.. :)

    

    Contact["name"] = "Vin.k.s"; If it helps, Mark as answer to help others..

    Tuesday, August 28, 2012 10:08 AM
  • Ok it's DONE..

    because of windows7 security i was unable to open a socket to send a E-Mail..

    I asked our Admin for priviledge.. and it worked..


    Contact["name"] = "Vin.k.s"; If it helps, Mark as answer to help others..

    • Marked as answer by ViN.k.S Thursday, August 30, 2012 7:34 AM
    Thursday, August 30, 2012 7:34 AM