Home > Ask the Microsoft .Net Development Experts > Visual Studio .NET Questions & Answers > The easiest way to send e-mails from VS.NET
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

The easiest way to send e-mails from VS.NET

Samuel Matzen EXPERT RESPONSE FROM: Samuel Matzen

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 19 July 2004
I'm trying to use a Visual Studio .NET 2003 Web application to send e-mails to addresses I get out of my database. What is the simplest way send e-mails like these in Visual Studio? If possible, I would prefer not installing any additional software.

>
Sending Email from any .NET application is fairly straight-forward and uses behavior built into the System.Web Assembly.

You need to create a new instance of the SystemWeb.Mail.MailMessage object and set the From, To, Subject and Body properties. This message can then be sent through an SMTP server by setting the SmtpServer property of the System.Web.Mail.SmtpMail object and invoking the Send method.

The following code shows you how to set the properties and invoke the methods. It even shows you how to add an attachment:

''' delcare a new mail message
Dim aMailMessage As New System.Web.Mail.MailMessage

''' set the from address
aMailMessage.From = "me@somewhere.com"

''' set the to address and subject
aMailMessage.To = "smatzen@slm.com"
aMailMessage.Subject = "This is a test email message."

''' send in Text format
aMailMessage.BodyFormat = System.Web.Mail.MailFormat.Text

''' set the body text (Remember you need to keep your paragraphs to under 1000 characters)
aMailMessage.Body = "This is the text of the email message."

''' add an attachment if you want to
aMailMessage.Attachments.Add(New System.Web.Mail.MailAttachment("C:Test.txt", System.Web.Mail.MailEncoding.Base64))

''' send the email
System.Web.Mail.SmtpMail.SmtpServer = "smtp.sbcglobal.net"
System.Web.Mail.SmtpMail.Send(aMailMessage)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Visual Studio .NET
Load a DSL domain model instance file programmatically
Calling via command prompt from ASP.NET
On line-by-line analysis in VS .NET
Best approach for merging text files using arrays
Descriptions of symbols in the class view of a .NET solution
What's the best approach for enumerating network resources?
How to enable a line-by-line code walkthrough
Changing a C++ Makefile project to a Utility project
How can I configure Visual Studio.NET 2002 to use the .NET Framework 1.1?
Changing a datagrid column to read-only=false based on variable

Visual Studio .NET
Load a DSL domain model instance file programmatically
Best approach for merging text files using arrays
Descriptions of symbols in the class view of a .NET solution
What's the best approach for enumerating network resources?
How to enable a line-by-line code walkthrough
Changing a C++ Makefile project to a Utility project
How can I configure Visual Studio.NET 2002 to use the .NET Framework 1.1?
Changing a datagrid column to read-only=false based on variable
Resizing controls on a form
No extensibility folders

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts