There was a problem loading the comments.

Sending mail from ASP.NET / C#

Support Portal  »  Knowledgebase  »  Viewing Article

  • 31 December 1969 6:00 PM

It is mandatory to use SMTP authentication for sending out emails through our servers. You can use the below sample C# code for the same (by making required modifications):

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();

MailAddress fromAddress = new MailAddress("", "From Name");

// You can specify the host name or ipaddress of your server
smtpClient.Host = ""; //you can also specify mail server IP address here

//Default port will be 25
smtpClient.Port = 25;

NetworkCredential info = new NetworkCredential("", "smtp-password");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = info;

//From address will be given as a MailAddress Object
message.From = fromAddress;

// To address collection of MailAddress
message.Subject = "Your subject";

// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("")

//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;

// Message body content
string ss_body = "body of email is here";
message.Body = ss_body;

// Send SMTP mail

Share via
Thank you for your feedback on this article.

Related Articles

© Softsys Hosting