Start New Discussion within our Web Development Community

I am trying to write a smiple email web program. Whenever I try to get an out going email I keep getting the general message that the computer is denying me access.

"No connection could be made because the target machine actively refused it " I have tried this at different locations.

String to, body, from, subject;

            to = TextBoxTo.Text;
            from = TextBoxFrom.Text;
            subject = TextBoxSubject.Text;
            body = TextBoxBody.Text;

            MailMessage mailMessage = new MailMessage();
            mailMessage.To.Add(new MailAddress(to));
            mailMessage.From = new MailAddress(from);
            mailMessage.Subject = subject;
            mailMessage.Body = body;

            SmtpClient smtpClient = new SmtpClient();


        <network host="" port="587" userName="" password="pizza" enableSsl="true" />

It is also possible that there is a firewall between your server and gmail blocking access.

You may want to try replacing lines 17-18 with:

SmtpClient smtp = new SmtpClient();
smtp.Host = "";
smtp.Credentials = new System.Net.NetworkCredential
smtp.EnableSsl = true;

I have done it using smtp.Credential,, using Appsetting in WEb.config. But at school or my house I get the error the receiving computer is blocked

//smtpClient.Port = 587;
            //smtpClient.Host = "";
            //System.Net.NetworkCredential NC = new NetworkCredential("", "");
            //smtpClient.Host = ConfigurationManager.AppSettings["SMTP"];
            //smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["from"], ConfigurationManager.AppSettings["pwd"]);
            //smtpClient.EnableSsl = true;
            //smtpClient.UseDefaultCredentials = false;
            //smtpClient.Credentials = NC;
            //smtpClient.Credentials = new NetworkCredential("", "");

    <add key="smtp" value=""/>
    <add key="to" value=""/>
    <add key="from" value=""/>
    <add key="pwd" value=""/>
    <add key="port" value="587"/>
This article has been dead for over six months. Start a new discussion instead.