Silver
Silver

Reputation: 453

creating smtp server and read the emails c#

I am given a task to create a new smtp mail server which can receive mail using C#.

While going through the articles i read we can send emails via SMTP but we have to receive or read using POP.

I was directed to links by some stackoverflow already existing questions: Rnwood and sourceforge

Rnwood I am sorry but i did not understand how to use it. source forge the msi asked to download if we run it, it asks to download framework 1.1.4322 which will not install in my system and throw error.

Usually there are codes for sending messages so I tried msdn example I used localhost as the server and 587 as the port. which gives me error (for any port 587,25) error EHLO I also found an article here which actually monitors the localhost and specified port when I try to run the msdn code. enter image description here

But still I am unable to send email to test in any way.

So is there any way I can code to set up smtp in my own server and receive email and test.

Upvotes: 4

Views: 10900

Answers (2)

Aydin
Aydin

Reputation: 15284

Setting up and configuring a mail server is a completely different ball game than just sending or reading emails from an existing IMAP / POP3 server.

A mail server consists of a number of components such as:

  • A Mail Transfer Agent (MTA) that handles SMTP traffic and which is responsible for sending email from your users to an external MTA and to receive email from an external MTA.

  • Mail Delivery Agent which retrieves mail from the MTA and places it in the recipient's mailbox.

  • A domain name with appropriate DNS records and an SSL certificate.

  • A server that provides IMAP / POP3 functionality.

In short... stick to publicly available mail servers...


In your post you referenced the SmtpClient from the .NET framework. That library is used to connect to an existing mail server. You can use it like this.

MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]", "Your name");

MailAddress recipientsMailAddress = new MailAddress("[email protected]");
message.To.Add(recipientsMailAddress);
message.Subject = "The subject of your email";
message.Body = "The body / content of your email";
message.IsBodyHtml = false; // You can set this to true if the body of your email contains HTML

SmtpClient smtpClient = new SmtpClient
{
    Credentials = new NetworkCredential("Your username/email", "Your password"),
    EnableSsl = true, // Will be required by most mail servers
    Host = "The host name of the mail server", // 
    Port = 465 // The port number of the mail server
};

smtpClient.Send(message);

If you have a Gmail account, you can use their SMTP server in your C# application, simply use these settings and it should all work.

Hostname: smtp.gmail.com
Port: 587
Username: [email protected]
Password: ********
RequireSSL: true

Upvotes: 3

Nekresh
Nekresh

Reputation: 2988

Have a look at SmtpListener, I think it does what you want. It isn't a standard email server which will receive new emails throught SMTP, store them on disk and allow you to retrieve them using POP.

SmtpListener will create a SMTP server that will receive email and allow you to react to any new email through code.

However, please note that you will have to configure it in your production environment like a real SMTP server, including MX DNS entries.

Upvotes: 0

Related Questions