Reputation: 640
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
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
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