简体   繁体   中英

Send email via asp.net throw exception

I wrote this code in asp.net for sending email:

MailMessage mailObject = new MailMessage("a@b.com(I use fake email, exactly this email)", "info@mydomain.com", "contact us", "Test message");
SmtpClient smtpC = new SmtpClient("my smtp server name");
smtpC.Send(mailObject);

But I receive this exception:

System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Also I can not connect to my "smpt server name" via tel net:

telnet SMTPServerName 25 Connecting To SMTPServerName...Could not open connection to the host, on port 25: Connect failed

Is there any standard for troubleshooting this?

Most likely the server name or port is incorrect. Make sure you can send from an SMTP client before troubleshooting further in your code.

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