I have started with simple c# mail application, to send message from one computer to the other, which are connected by LAN.
My question is: how to define addresses, or mailmessage.from and mailmessage.to.
I have tried with their addresses, but nothing...

Pete

Recommended Answers

All 4 Replies

You do not send E-Mail to other computers per se, you send it to their responsible mail server. So depending on your network you probably have an email server for the LAN (your workplace?) or share a common ISP email address.

To send an email via code:

using (MailMessage msg = new MailMessage())
{
  msg.From = new MailAddress("from@who.com");
  msg.To.Add(new MailAddress("to@who.com"));
  msg.Subject = "Hello World";
  msg.Body = "Test";
  SmtpClient cli = new SmtpClient("smtpserver.hostname.com");
  cli.Send(Message);
}

Sknake,

I'm at the beginning, so sorry for stupid questions.
First of all: do I need an e-mail server on all machines or only on server?
What kind of e-mail server do I need?
How do You define domains, such as: from@who.con....
Can I do it without defining domain for SmtpClient

Pete

No, you only need a single email server for all the machines. You can use any type of email server you want such as Microsoft Exchange or Linux postfix, qmail, sendmail. More than likely you don't want to set up your own email server if you're not familiar with them, they require a fair amount of knowledge to set up. You cannot send an email without an smtp client unless you have a local exchange server that has other protocols for sending email.

The domains are defined based on registrars, each country owns a domain for their country extension such as .us .au .kr .cn etc. www.godaddy.com is one registrar where you can purchase a domain, such as pete.com (i'm sure it has already been taken). Once you purchase a domain you have to set up glue records for your nameserver at the registrar and point it to your DNS server. In your DNS server you need to setup an MX record that points to a hostname which has an A record, after that email will be send to the hostname defined in your MX record. If you think this sounds a little bit complicated this is only scratching the surface of what it requires to set up a domain and an email server....

What are you trying to accomplish? I know you want to send email, but for what purpose? More than likely your ISP provided you with an email account you can use but the SmtpClient only sends mail. To read email in C# will take considerably more effort. You're better off sticking to a retail application such as outlook for this.

My task is to develop ad-hoc network, of WLAN type, where members will be able to comunicate using standard messages relying on TCP/IP (asynchronous sockets in C#). I have written the code, tested it and it works (so far only on LAN, soon I'm going to test it on WLAN).
Now, customer wants to add mailing feature in the application. User will be able to send standard messages and attachments. Once again, I used C#, but stumbled at the very beginning with smtp send method, where it requires host and destination... You know the rest.
Could You give me some advice, what should I do...

Thanks

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.