Posts

Showing posts with the label mail

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 smt...