Form Email

Hi im I need help with contact form functionality for it to send anything that im missing from my Java please help it is not sending…

Imports System.Net.Mail

Public Class register
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(sender As Object, e As EventArgs)

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        Try
            Dim mailMessage As New MailMessage()
            mailMessage.From = New MailAddress("myemail@mydomain.com")
            mailMessage.[To].Add("myemail@mydomain.com")
            mailMessage.Subject = txtSubject.Text

            mailMessage.Body = "<b>Sender Name : </b>" + txtname.Text + "<br/>" + "<b>Sender Email : </b>" + txtEmail.Text + "<br/>" + "<b>Comments : </b>" + txtComments.Text
            mailMessage.IsBodyHtml = True


            Dim smtpClient As New SmtpClient("smtpout.secureserver.net ", 465)
            smtpClient.EnableSsl = True
            smtpClient.Credentials = New System.Net.NetworkCredential("myemail@mydomain.com", "password")
            smtpClient.Send(mailMessage)

            Label1.Text = "Thank for contacting us"
            Label1.ForeColor = System.Drawing.Color.Blue

            txtname.Enabled = False
            txtEmail.Enabled = False
            txtComments.Enabled = False
            txtSubject.Enabled = False
            Button1.Enabled = False
        Catch generatedExceptionName As Exception
            ' Log - Event Viewer or table 
            Label1.ForeColor = System.Drawing.Color.Blue
            Label1.ForeColor = System.Drawing.Color.Red
            Label1.Text = "There is an unknown problem. Please try later"
        End Try
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub

    Protected Sub ddlCountries_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub

    
End Class


'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================

There is no Java or JavaScript in the code you posted. All you posted was VB.NET code.

Did you paste the wrong thing?

Oh sorry I named the wrong thing it is suppose to be VB.NET code.

No, there’s not really much here to go on. I’ve even worked in .NET in the past and I have a hard time reading VB.NET. :slight_smile:


Also, just for future reference. Java and JavaScript are not similar things. Just remember:

Java is to JavaScript as Ham is to Hamster.

Oh I see thanks anyways. Yeah its pretty difficult to understand.

Are you getting an error of some sort? A build error? Anything that we can go on?

BTW, if that was your real username and password for that email address, you should change it now! I edited your post to take it out.

I get this error : There is an unknown problem. Please try later

whoops yeah thanks my bad.

Okay, so you are getting an exception, now we need to figure out what it is.

Replace the following

        Catch generatedExceptionName As Exception
            ' Log - Event Viewer or table 
            Label1.ForeColor = System.Drawing.Color.Blue
            Label1.ForeColor = System.Drawing.Color.Red
            Label1.Text = "There is an unknown problem. Please try later"
        End Try

with

        Catch generatedExceptionName As Exception
            ' Log - Event Viewer or table 
            Label1.ForeColor = System.Drawing.Color.Blue
            Label1.ForeColor = System.Drawing.Color.Red
            Label1.Text = "There is an unknown problem. Please try later"
            throw
        End Try

Or you can assign generatedExceptionName.Message to Label1.Text

This is what I get with the new exception code.

http://iogproducts.com/FORMA.aspx

Try sending it.

It isn’t throwing the exception… so that must not be the latest code.

        Catch generatedExceptionName As Exception
            ' Log - Event Viewer or table 
            Label1.ForeColor = System.Drawing.Color.Blue
            Label1.ForeColor = System.Drawing.Color.Red
            Label1.Text = generatedExceptionName.Message
            throw
        End Try

Ok I put it now. Now it gives me this…

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error: 


Line 37:             Label1.ForeColor = System.Drawing.Color.Red
Line 38:             Label1.Text = generatedExceptionName.Message
Line 39:             Throw
Line 40:         End Try
Line 41:     End Sub

You need to talk to your host. As they are limiting your permission level. You need at least medium trust level in .NET to use SMTP Permission.

Oh ok did not know that thanks. So do I keep this code in there? or take it off?

Remove the word “throw”, as that will expose issues to everyone if you leave it in there.

Ok. Thanks.

this is coding by VB.Net, you can code in C#?

Hi @nhubv_it, if you have a specific question that is in C#, please post a new topic. I’ll gladly review it.

You can use a code converter to C# http://converter.telerik.com/