简体   繁体   中英

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

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.

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,

First and foremost, as mentioned by others, you need to be running a mail server on localhost for this to work. Port 25 is the default post for SMTP but that doesn't mean there's a mail server standing by. You can use a free e-mail address to make sure the e-mail really gets delivered and the only change you'd need is to add your account credentials (see this tutorial for reference ). For the port information, check the e-mail provider's instructions for setting up e-mail clients, which should be available in the Settings menu of just about any e-mail provider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM