Thursday, March 22, 2012

wanna send an email

i have a webform with the txtboxes
txtName
txtFrom
txtTo
txtCc
txtComments
i have the following code.
any help at all would be greatly appreciated
i have a few errors so as i cannot run it the errors shall be in red below

PublicClass WebForm1

Inherits System.Web.UI.Page

PrivateSub Page_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load

'Put user code to initialize the page here

EndSub

PublicSub sendmail()

Dim objEmailAsNewMailMessage - (type mail message is not defined)

objEmail.To = txtTo.Text

objEmail.From = txtFrom.Text

objEmail.Cc = txtCc.Text

objEmail.Subject = "Test Email"

objEmail.Body = txtName.Text & ", " & txtComments.Text

' objEmail.Priority = MailPriority.High

SmtpMail.SmtpServer = "localhost" -smtpmail not declared

Try

SmtpMail.Send(EMail) -also not declared

Response.Write("Your E-mail has been sent sucessfully Thank You")

Catch excAs Exception

Response.Write("Send failure: " + exc.ToString())

EndTry

EndSub

EndClass


You forgot to declare the full namespace name, in other word use Imports statement as shown below

Imports System.Web.Mail
PublicClass WebForm1

Inherits System.Web.UI.Page

HTH
regards

0 comments:

Post a Comment