stackuser3
stackuser3

Reputation: 9

How to send mails through smtp in c#

How to send mails through smtp in c#

Upvotes: 0

Views: 571

Answers (3)

Nick Allen
Nick Allen

Reputation: 12230

System.Net.Mail.MailMessage in conjunction with System.Net.Mail.SmtpClient

MailMessage mail = new MailMessage();
mail.From = new MailAddress("from address");
mail.Subject = "subject";
mail.Body = "body";
mail.IsBodyHtml = IsHtml;
mail.To.Add("targetaddress");

SmtpClient mailClient = new SmtpClient("smtphost");
mailClient.Credentials = new NetworkCredential("username", "password", "domain");

try
{
    mailClient.Send(mail);
}
catch (Exception ex)
{
    throw ex;
}
finally
{
    mailClient = null;
}

Upvotes: 3

Pieter Germishuys
Pieter Germishuys

Reputation: 4886

Have a look at the System.Net.Mail.SmtpClient reference. It should be what you are looking for

Upvotes: 0

Oded
Oded

Reputation: 499302

You use the System.Net.Mail.MailMessage class to create the message.

Then send it using the SmtpClient class to do the actual sending.

There are examples in the linked pages.

Upvotes: 2

Related Questions