Sudix
Sudix

Reputation: 640

SMTP server name and port

I am trying to send an email using a simple button in asp.net. But I am getting following error-"The transport failed to connect to the server".

  SmtpMail.SmtpServer = "localhost";

I've used localhost because,I don't know smtp server name of my computer.. how can i fix it? how can I know the SMTP server name?? My os is win xp hope someone can help me...

Upvotes: 3

Views: 1768

Answers (3)

IrishChieftain
IrishChieftain

Reputation: 15253

To test email locally set up a drop folder called 'maildrop' on your C:\ drive and add the following to your Web.Config file:

<system.net>
    <mailSettings>
        <smtp deliveryMethod='SpecifiedPickupDirectory'>
            <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop" />
        </smtp>
    </mailSettings>
</system.net>

ASP.NET: Using pickup directory for outgoing e-mails

UPDATE:

You should be using the newer email library...

using System.Net.Mail;

MailMessage msg = new MailMessage(); 
msg.To = "[email protected]"; 
msg.From = "[email protected]"; 
msg.Subject = "hi"; 
msg.Body = "yes"; 

SmtpClient smtpClient = new SmtpClient("localhost");
smtpClient.Send(msg);

Upvotes: 1

Felipe Ardila
Felipe Ardila

Reputation: 3004

You need a SMTP server on your machine before do that.

Upvotes: 0

Brian Agnew
Brian Agnew

Reputation: 272347

Standard SMTP runs on port 25. If you don't have anything listening on port 25 on your machine, then you likely don't have an SMTP server running. Try:

telnet localhost 25

and see if that connects to something. I ssupect not (i.e. you don't have an SMTP server on localhost)

Upvotes: 0

Related Questions