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 = "firstname.lastname@example.org" ''' set the to address and subject aMailMessage.To = "email@example.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)
Related Q&A from Samuel Matzen
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.