Created
January 4, 2016 04:12
-
-
Save darbio/1cdbf2700013e37e530e to your computer and use it in GitHub Desktop.
Code for http://darb.io/blog/2012/02/24/50-sending-an-email-with-an-attachment-from-workflow-foundation/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set the variables | |
string smtpAddress = "mail.example.com"; | |
string fromAddress = "from@example.com"; | |
// Create the SMTPClient | |
var smtp = new SmtpClient(smtpAddress); | |
smtp.Credentials = new NetworkCredential("username", "password"); | |
// Construct the MailMessage | |
var mail = new MailMessage(); | |
mail.From = new MailAddress(fromAddress); | |
mail.To.Add("to@example.com"); | |
mail.Subject = "Email subject here"; | |
mail.Body = "Body"; | |
// Attach the files | |
mail.Attachments.Add(new Attachment("filename")); | |
mail.Attachments.Add(new Attachment("filename")); | |
// Send the MailMessage | |
smtp.Send(mail); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment