Send an email from a webpage with

July 15, 2010 - 15:06

Emailing with .net is fairly simple. You will also need to know an SMTP mailserver which you have permission to relay from, otherwise you will recieve an error 550.

<% @Import Namespace="System.Web.Mail" %>

SmtpMail.SmtpServer = ""
Dim OrderMail as new MailMessage
OrderMail.To = ""
OrderMail.From = ""
OrderMail.Subject = "Subject here"
OrderMail.BodyFormat = MailFormat.Html
OrderMail.Body = "message here"

Firstly the smtp server is specified the rest is self explanatory, however you will need to have valid email addresses for this to run without any errors. What i usually do is put a try/catch clause around the SmtpMail.Send as usually if the from address is taken from a webform, most users won't enter a valid email address.

© 2011