-3

Possible Duplicate:
Send email with attachment from WinForms app?

Here is my script:

     var fromAddress = new MailAddress("myemail@gmail.com");
     var toAddress = new MailAddress("myemail@gmail.com");
     const string fromPassword = "mypassword";
     const string subject = "Subject";
     const string body = "Body";

       var smtp = new SmtpClient
       {
           Host = "smtp.gmail.com",
           Port = 587,
           EnableSsl = true,
           DeliveryMethod = SmtpDeliveryMethod.Network,
           UseDefaultCredentials = false,
           Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
       };
       using (var message = new MailMessage(fromAddress, toAddress)
                 {
                     Subject = subject,
                     Body = body,
                 })

       {
           smtp.Send(message);
       }

It works well, yet I am yet to come up with a way to add an attachment. Yes, I know this site has examples, but I cannot find one that will send an attachment

Community
  • 1
  • 1
user1797443
  • 236
  • 1
  • 5
  • 15
  • That's a script? It looks just like a computer program to me. – John Saunders Dec 11 '12 at 02:08
  • Try a Google search with "c# send attachment". The first set of results should give you what you want. – tsells Dec 11 '12 at 02:10
  • -1 absolutely no research effort: http://www.google.com.au/search?q=send+email+attachment+stackoverflow+c%23 -> first link: http://stackoverflow.com/questions/2204698/send-email-with-attachment-from-winforms-app – Jeremy Thompson Dec 11 '12 at 02:27

1 Answers1

1

Use the Attachments property.

John Saunders
  • 160,644
  • 26
  • 247
  • 397