Friday 18 January 2008

Sending Email

Here's a quick rundown on how to send an email from your aspx page.

In the code behind call the namespace:

Imports System.Net.Mail

The OnClick event for your Send button could look something like this:

Dim msgBody As String
msgBody = "THE BODY OF YOUR MESSAGE GOES HERE"

Dim msg As New MailMessage
msg.From = New MailAddress("fromthisguy@whatever.com")
msg.To.Add(New MailAddress("tothisguy@thisguyswebsite.com")
msg.Subject = "SUBJECT FOR MESSAGE GOES HERE"
msg.Body = msgBody
Dim mc As New SmtpClient
mc.Send(msg)

Last but not least you also need to set the smtp settings for the web application in the web.config file, the quickest way to do this is using the
Web Site Administration Tool , here's an example of web.config settings anyway:


<system.net>
<mailSettings>
<smtp from="info@wrapturegifts.co.uk">
<network host="YOUR MAILSERVER ADDRESS HERE" password="YOUR SMTP EMAIL PASSWORD HERE" userName="YOUR SMTP USERNAME HERE" />
</smtp>
</mailSettings>
</system.net>

No comments: