Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

ASP.NET: Send an email

From Wiki

Jump to: navigation, search


Summary: A simple function to send an email

  1. Public Sub sendEmail(ByVal EmailAddress As String, ByVal Subject As String, ByVal EmailBody As String, ByVal FromAddress As String)
  2.     Dim Message As New MailMessage(FromAddress, EmailAddress, Subject, EmailBody)
  3.     Dim smtp As New SmtpClient("127.0.0.1")
  4.     Dim NetworkCredentials As New System.Net.NetworkCredential
  5.  
  6.     ' If you are in a development environment without an SMTP server, you can use
  7.     ' the two lines below to send the email to a file
  8.     ' smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
  9.     ' smtp.PickupDirectoryLocation = "c:\emails"
  10.  
  11.     NetworkCredentials.UserName = "example"
  12.     NetworkCredentials.Password = "example"
  13.     smtp.Credentials = NetworkCredentials
  14.     smtp.Send(Message)
  15. End Sub

NOTE: Remember to add "Imports System.Net.Mail" to your page/class.


This Hack is part of the ASP.NET Hacks collection

451 Rating: 2.7/5 (9 votes cast)