Runtime exception is:
The transport failed to connect to the server
开发者_开发百科
Please give me any of your suggestions.
As I am working on my own pc so i do not have any mail server so i put the name of my internet broadband provider (SmtpMail.SmtpServer = "smtp.virginmedia.com";
) Is it the right way?
Make sure that the server accepts your connection.
The first step is to read the error message.
At a guess, I would say that this error is caused because the web application is unable to connect to a particular server. Then we go look up the documentation for SmptMail class to see what could cause that.
The first thing we see is that the System.Web.Mail API is obsolete and that you should use System.Net.Mail.SmtpClient instead.
It could be because
- your smtp server name does not resolve
- your smtp server ip or port is incorrect
- your smtp server requires authentication
- your smtp server requires ssl
You will need to check with your provider to see if they support SMTP and to get the correct server address. You might consider installing an SMTP server on your machine.
You might also want to try using an SMTP test tool. This is a quick and easy way to test different settings without having to deal with any other possible issues in your own code. There are a few good ones out there. I've used one before but I don't remember which one, sorry.
I'd recommend that you try using System.Net.Mail instead of SmtpMail, but that may not solve your connection problem.
Before you get too wrapped up in diagnosing connection problems in your project, make sure you can send a message using a standard email client like Outlook or Pine. Then copy your settings from the mail client into your code or into your web.config file to set the SMTP server connection.
If you are using a hosting service they likely have permissions fairly strict on the server.
In a lower trust mode on the server, all SMTP connections must be setup using web.config. If you try to pass a address inline in your code you violate trust conditions.
SMTPClient Half Working \ Half Not
精彩评论