C# – System.Net.Mail.SmtpException: Failure sending mail. No connection could be made because the target machine actively refused it 127.0.0.1:25

asp.netcemailexceptionforms

I have set up a test email form submission and continue to get the following error message no matter how many ways i try

System.Net.Mail.SmtpException: Failure sending mail. —> System.Net.WebException: Unable to connect to the remote server —> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) — End of inner exception stack trace — at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) — End of inner exception stack trace — at System.Net.Mail.SmtpClient.Send(MailMessage message) at frmQuote.btnSubmit_Click(Object sender, EventArgs e) in c:\Users\jack\Documents\Visual Studio 2013\WebSites\firstarPrecision\frmQuote.aspx.cs:line 28

If it is needed here is the C# code that i am using to submit the form

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class frmQuote : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            using (MailMessage message = new MailMessage())
            {
                message.From = new MailAddress(txtEmail.Text.ToString());
                message.To.Add(new MailAddress("swdlodonnell@gmail.com"));
                //message.CC.Add(new MailAddress("copy@domain.com"));
                message.Subject = "Quote request from " + txtCompanyName.Text.ToString();
                message.Body = txtContact.Text.ToString();
                SmtpClient client = new SmtpClient();
                client.Host = "127.0.0.1";
                client.Send(message);
            }
        }
        catch(Exception ex) {
            Response.Write(ex);
        }
    }
}

I have tried several ways and it seems to me like i am being blocked by an antivirus/firewall, thanks.

Best Answer

You are triyng to send it through an SMTP on your local machine (127.0.0.1) which I assume does not have an smtp server running.

If you need a facility to send e-mails easily through SMTP I recommend mandrill smtp, very easy and free to use,

Related Topic