Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending a simple mail in ASP.NET

    Hello everyone,

    Would anyone disagree that the following code for sending an email from a web site contact page is correct (classic three text box scenario; sender's email address, subject and message body):

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Build a MailMessage
    Dim mailMessage As System.Net.Mail.MailMessage = New_ System.Net.Mail.MailMessage
    mailMessage.From = txtEmail.txt
    mailMessage.To = "enquiries@mywebsite.com"
    mailMessage.Subject = txtSubject.tex

    mailMessage.Body = txtMessage.Text

    Dim smtp As New SmtpClient("smpt.fasthosts.co.uk")
    smtp.Send(mailMessage)

    Try
    Label1.Text = "Your Mail was sent."
    Catch exp As Exception
    Label1.Text = "There was and error Sending the mail: " & exp.Message
    End Try
    End Sub

    Many thanks in advance

  • #2
    New Coder
    Join Date
    Nov 2006
    Posts
    47
    Thanks
    2
    Thanked 1 Time in 1 Post
    What error are you getting?

    I would remove the underscore after 'New'.

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply Erica. I managed to get it functioning not too long after the post. Have another problem though (a seemingly huge one), but will post it under the appropriate heading.

    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •