Fail To Sent Email From Asp.net Page RRS feed

  • Question

  • User1109811461 posted

    hi all expertise

    i got problem when sent email from asp.net page below is my code, need help regarding this problem

     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim sb As New StringBuilder

                SendMail("myemailaddress@gmail.com", sb.ToString)
            Catch ex As Exception
                Label1.Text = "Failed"
            End Try

        End Sub

        Protected Sub SendMail(ByVal from As String, ByVal body As String)

            Dim Email As New MailMessage("myemailaddress@gmail.com", txtEmail.Text, "Subject of Email", body)
            Dim smtpClient As SmtpClient = New SmtpClient
            smtpClient.Host = "smtp.gmail.com"
            smtpClient.EnableSsl = True

            Dim credentials As New System.Net.NetworkCredential("username", "password")
            smtpClient.Credentials = credentials

            Label1.Text = "Success"

        End Sub

    Saturday, December 29, 2012 10:57 PM


All replies

  • User197322208 posted

    Catch ex As Exception
                Label1.Text = "Failed" + ex.Message
            End Try

    What's the message?

    Saturday, December 29, 2012 11:05 PM
  • User1109811461 posted

    hi ignatandrei

    thanks for reply, i just got this is the error message when i implement you code:

    Failure sending mail

    need help, i really need to implement this ignatandrei

    Sunday, December 30, 2012 12:20 AM
  • User-1171043462 posted

    Remove the credentials from Web.Config file and set them in code. Refer

    Send Email using Gmail in VB.Net

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 30, 2012 1:22 AM
  • User1109811461 posted

    hi mudassarkhan

    you resolve my problem tq so much , really appreciate itCool

    Sunday, December 30, 2012 2:11 AM