C# send email with .net framework

So I have come across a need to send some email via the .net framework to report status to a disto list we have for a product we support. The following code below shows the basics of sending a simple text email with 1 attachment. The values being assigned to the message are parameters coming from a function. You can assign any string value you want to them. All this can be found in the using System.Net.Mail namespace.



// build the mail message
MailMessage mailMessage = new MailMessage();

mailMessage.From = new MailAddress( From );

// this can be one at a time, or a , delimited list
foreach( string toAddress in ToAddresses )
{
try
{
mailMessage.To.Add( new MailAddress( toAddress ) );
}//end try
catch( Exception )
{
// do something with your error
}//end catch
}//end foreach

mailMessage.Subject = SubjectLine;

mailMessage.Body = Body;

// add the attachment
mailMessage.Attachments.Add( new Attachment( AttachmentLocation ) );

// send the message via the smtp server
SmtpClient client = new SmtpClient( SMTP, port );
client.Send( mailMessage );

Comments

Anonymous said…
Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Popular posts from this blog

String.Replace vs Regex.Replace

C# Producer Consumer using Rabbit MQ

C# Form Application in Kiosk Mode/Fullscreen