Handling email in C #

I need to know the name of an object to handle emails in C # /. NET Framework.

+1


a source to share


5 answers


You need the System.Net.Mail namespace.

Here's an example from the ScottGu 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);

      

+6


a source


System.Net.Mail is a namespace for search. Start with SmtpClient or MailMessage .



+3


a source


In addition to Ekeko's answer, if you want 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 if your server requires it.

client.Credentials = new NetworkCredential("username", "password");

      

+2


a source


These answers assume that you are asking about SMTP processing. POP3 is not natively handled in the .NET environment. You will have to purchase a third party library. I would recommend the Ostrosoft POP3 library.

0


a source


There are a bunch of questions on Stack Overflow describing how you can submit.

0


a source







All Articles