1

I need to know the object name for handling emails in C#/.NET Framework.

Helen
  • 87,344
  • 17
  • 243
  • 314

5 Answers5

6

You need the namespace System.Net.Mail.

Here is an example from the ScottGu's blog.

MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com"); 

message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com")); 

message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";


SmtpClient client = new SmtpClient();
client.Send(message);
eKek0
  • 23,005
  • 25
  • 91
  • 119
3

System.Net.Mail is the namespace to look in. Start with SmtpClient or MailMessage.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
2

In addition to Ekeko's answer if you would like to use an external mail server you must specify the host in the SmtpClient constructor.

SmtpClient client = new SmtpClient("mail.yourmailserver.com");

And you might also need authentication to be specified if your server requires it.

client.Credentials = new NetworkCredential("username", "password");
j0tt
  • 1,108
  • 1
  • 7
  • 16
0

These answers are assuming that you are asking about SMTP handling. POP3 is not handled natively in the .NET framework. You will have to purchase a third-party library. I'd recommend the Ostrosoft POP3 library.

hmcclungiii
  • 1,765
  • 2
  • 16
  • 27
0

There is a bunch of questions in stack Overflow that describes how you can send.

Community
  • 1
  • 1
ecleel
  • 11,748
  • 15
  • 48
  • 48