hi friends...
i m new in c#.net..
i m going to develop some basic application like sending email from my application...
i got some code from internet...
but i m facing problem regarding setting of SMTP server..
can anybudy tell how to find out SMTP server name of our local machine...
plz anybudy help is any related url or any code plz share with me...........

namespace WebMail
{
class Class1
{
static void Main(string[] args)
{
try
{
MailMessage oMsg = new MailMessage();
// TODO: Replace with sender e-mail address.
oMsg.From = "i_prashant11@rediffmail.com";
// TODO: Replace with recipient e-mail address.
oMsg.To = "indapure.prashant@gmail.com";
oMsg.Subject = "Send Using Web Mail";


// SEND IN HTML FORMAT (comment this line to send plain text).
oMsg.BodyFormat = MailFormat.Html;


// HTML Body (remove HTML tags for plain text).
oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>



// TODO: Replace with the name of your remote SMTP server.SmtpMail.SmtpServer = "MySMTPServer";//how to find SMTP server name of our local macine
SmtpMail.Send(oMsg);


oMsg = null;
//oAttch = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}

Thanks in advance.

Prashant Indapure

Dani AI

Generated

A short, practical checklist for finding and using an SMTP server from a C# app.

If you plan to send mail using a given From address, use the SMTP host that accepts and authenticates that address (your mail provider or your own mail server). There are three common sources for the SMTP hostname: the mail provider’s support pages, the hosting control panel/administrator for the server that hosts your domain, or a mail service you installed locally (Exchange, an SMTP feature, hMailServer, Postfix, etc.). If you pick the local-server route, confirm the service is actually installed and listening before you try to send from code.

Quick steps to discover the server name and test connectivity:

  • Check your mail provider’s documentation for “SMTP server” and required port/auth (providers normally list host, port, SSL/TLS and authentication details).
  • If you run your own mail host, inspect that server’s mail configuration (Exchange, IIS SMTP, hMailServer) to read the advertised hostname or FQDN.
  • Use DNS tools (nslookup/dig MX) to see mail exchangers for a domain (note: MX shows inbound mail servers and is only a hint for outbound/relay servers).
  • Test reachability from your machine (PowerShell Test-NetConnection -ComputerName smtp.example.com -Port 587 or telnet smtp.example.com 587) and check for firewall/ISP blocks.

A minimal, modern example using System.Net.Mail (replace host/creds/ports with the values you discover):

using System.Net;
using System.Net.Mail;

var client = new SmtpClient("smtp.example.com", 587) {
    Credentials = new NetworkCredential("username", "password"),
    EnableSsl = true
};

var mail = new MailMessage("from@example.com", "to@example.com", "Subject", "Body");
client.Send(mail);

Troubleshooting tips: capture the full exception and InnerException, check for authentication errors, blocked ports (ISP often blocks port 25), and required SSL/TLS or app-passwords (Gmail/Office365). For new projects consider using MailKit (recommended over SmtpClient for advanced scenarios). Relevant references: Microsoft SmtpClient docs (https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient) and the MailKit project (https://github.com/jstedfast/MailKit). This expands on ’s pointer and follows the local-server idea mentioned by and — but the key is to verify an actual SMTP host and working credentials before sending from C#.

Recommended Answers

All 3 Replies

Hi there Pash11, you may find the following URL useful:

Hope this helps!

i guess for the local machine you can always give 127.0.0.1,

If your local host address does not work, try the ip address of your server, this off course would work if the default smtp is install on your machine

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.