How to send Email from a .Net project?

Ricky White
Ricky White used Ask the Experts™
I would like to create a C#.Net project to send an email with an attachment.
Please advise how can this be achieved. Would VBScript be the easiest route?

Any links or resources would be appreciated.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
You can use the SmtpClient class (example at the bottom of the page) to send email--provided you have access to an SMTP server (of which there are several free ones you could use).
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Anuradha GoliSystems Development / Support Specialist

Import System.Web.Mail 

              Dim message As MailMessage
              message = New MailMessage ()
              message. To = "receiverID@domainName.Com"
              message. From = ""
              message. Subject = "Email Subject"
              message.BodyFormat = MailFormat.Html
              msgMail.Body = "<html><body><h2 " + 
                             "align = center>Hello World! " + 

  MailAttachment attachment1 =
   new MailAttachment (@"c:\My Documents\OfficeFile1.doc");
  // Add Another One...
  MailAttachment attachment2 = 
   new MailAttachment ("d:\\Documents\\asp.netTurorial.doc");
  message.Attachments.Add (attachment1);
  message.Attachments.Add (attachment2);

              SmtpMail.Send (message)
              response. Write ("<BR><font color=red" + 
                               " face=verdana size=2> " + 
                               "Sent the mails. </font>")

Open in new window

Most Valuable Expert 2012
Top Expert 2014


Thanks All!
Although all answers were helpful, I meant to select CodeCruiser's answer as the Best answer. Not sure how to change that.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial