looking for a brokerage account or IRA... click here Add To Favorites
return to index 

C# MailMessage Example

The following code snippet shows you how to use the mail function at its core level.

 
                    MailMessage mail = new MailMessage();
                    mail.To = to;
                    mail.Cc = cc;
                    mail.Bcc = bcc;
                    mail.From = from;
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.BodyFormat = MailFormat.Html;
                    SmtpMail.SmtpServer = "your server (localhost)";
                    SmtpMail.Send(mail);

If you need to use authentication in your mail message, you can achieve that by implementing the following commands.

 
                    MailMessage mail = new MailMessage();
                    mail.To = to;
                    mail.Cc = cc;
                    mail.Bcc = bcc;
                    mail.From = from;
                    mail.Subject = subject;
                    mail.Body = body;
                    mail.BodyFormat = MailFormat.Html;
                    SmtpMail.SmtpServer = "your server (localhost)";
                    SmtpMail.UseDefaultCredentials = false;
                    System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(user, password);
                    SmtpMail.Credentials = SMTPUserInfo;
                    SmtpMail.Send(mail);

Additional Interesting Articles

SQL Create Procedure
C# DataSet v DataReader
AJAX Javascript Functions
MS-DOS Command Descriptions
Looping Through a SQL Result in C#
C# Regular Expression Example

©2008 AndrewKimball.com