954,577 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sending Email

A user have to register to the site using Her existing email address as a user name so I need to send an email to the user's email address once her registration to my site is successful can anyone provide me with a code ASAP please

Traicey
Posting Whiz in Training
283 posts since Mar 2008
Reputation Points: 26
Solved Threads: 19
 

Hi

Try this code

Try
    '(1) Create the MailMessage instance
    Dim mm As New MailMessage(FromEmailAddress, ToEmailAddress)

    '(2) Assign the MailMessage's properties
    mm.Subject = "Test Email... "
    mm.Body = "This is a test message..."
    mm.IsBodyHtml = False

    '(3) Create the SmtpClient object
    Dim smtp As New SmtpClient

    'Set the SMTP settings...
    smtp.Host = Hostname.Text
    If Not String.IsNullOrEmpty(Port.Text) Then
        smtp.Port = Convert.ToInt32(Port.Text)
    End If

    If Not String.IsNullOrEmpty(Username.Text) Then
        smtp.Credentials = New NetworkCredential(Username.Text, Password.Text)
    End If

    '(4) Send the MailMessage (will use the Web.config settings)
    smtp.Send(mm)

    'Display a client-side popup, explaining that the email has been sent
    ClientScript.RegisterStartupScript(Me.GetType(), "HiMom!", String.Format("alert('An test email has successfully been sent to {0}');", ToAddress.Replace("'", "\'")), True)

Catch smtpEx As SmtpException
    'A problem occurred when sending the email message
    ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a problem in sending the email: {0}');", smtpEx.Message.Replace("'", "\'")), True)

Catch generalEx As Exception
    'Some other problem occurred
    ClientScript.RegisterStartupScript(Me.GetType(), "OhCrap", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
End Try


Mark as solve if it helps you

reach_yousuf
Junior Poster
195 posts since Sep 2007
Reputation Points: 12
Solved Threads: 38
 

Thanx a lot

Traicey
Posting Whiz in Training
283 posts since Mar 2008
Reputation Points: 26
Solved Threads: 19
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You