Hi!

I work in NIC (National Informatics Centre). When I try to send email thorugh my asp.net code, I am not abe to do so, reason most probably being the ports being blocked by our ISP. To confirm, I fired telnet command for ports 25, 465 and 587, but in all cases , I received the error "Could not connect". Is there any way to send email from my application inspite of the ports being blocked?

Dani AI

Generated

A few practical directions that add to what and already noted.

First, confirm and diagnose precisely before changing architecture. From the app host: verify DNS resolution, check outbound connectivity to a specific host/port (PowerShell Test-NetConnection on Windows or nc -vz on *nix), and inspect local firewall/proxy rules and any corporate gateway. Ask the network team or ISP for permission before scanning remote hosts — port scans can cause trouble.

If outbound SMTP is blocked and cannot be opened, the fastest server-side fix is to send mail over HTTPS instead of SMTP. Many transactional-email services expose an HTTP API on port 443 (which is almost always allowed). Example pattern in C# (use your config/secret store for the URL and API key):

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization =
  new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("EMAIL_API_KEY"));

var payload = new { to = "recipient@example.com", subject = "Hi", body = "Hello" };
var json = System.Text.Json.JsonSerializer.Serialize(payload);
var apiUrl = Environment.GetEnvironmentVariable("EMAIL_API_URL"); // set in config
var resp = await http.PostAsync(apiUrl, new StringContent(json, System.Text.Encoding.UTF8, "application/json"));
resp.EnsureSuccessStatusCode();

If an external API is not allowed by policy, another option is a small relay service you control on a host that can send SMTP outbound — the app posts to that relay over HTTPS and the relay performs SMTP delivery. Before using that, confirm the relay host permits outbound SMTP and configure authenticated relay, SPF/DKIM, and logging to avoid deliverability and abuse issues.

Recommended next steps: (1) run the connectivity checks from your app server, (2) try a simple HTTPS POST to a trusted endpoint to prove port 443 works, (3) prototype sending via an HTTP email API (using secrets, TLS, retries), and (4) if needed, open a support ticket with NIC/ISP to request a sanctioned relay or port exception.

Recommended Answers

All 7 Replies

To get mail from your web application to an SMTP server, you'll need to have that communication path open. The target SMTP server is going to have a limited set of ports listening for SMTP traffic. Those are the ports that you can use to send mail. If your ISP blocks these ports, then you cannot send traffic on those ports to this target system.

You would have to find another target system that you can communicate with on a different port that your ISP allows you to send traffic on.

Thanks for replying. Is there any way I can find which ports are open for communication?

You can run a port scanner against the target machine but I would not suggest you do this without their knowledge or consent. port scanning is not usually well received. In any case, just knowing what ports are open is not going to satisfy your requirements. For exapmle, say the target server has port 80 open (because its running a web server). Sending mail to port 80 isnt going to do you any good since the application on that target server is not expecting SMTP packets.

Your first step is to determine what ports on the target server are used for SMTP services. Then figure out if your ISP allows traffic outbound from you to that server on the ports in question.

I would assume that your ISP has an SMTP server that they allow their customers to use? If so, send mail directly to that SMTP server (smart host). Let your ISP relay your mail.

Thank you so much!

Can I manually open ports?

A port, more specifically a socket (IP+port) is created by the app/service running on the host which will accepted traffic from clients. So opening a port means you start a program that establishes the socket.

You could always let the client do the work...

<a href="mailto:me@somewhere.com?subject=Mysubject">Mail Me</a>

OK it depends on them having an email client installed and you will have to monitor the account...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.