Submit Form Not Working

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I am trying to use the following code to let users of my program send emails to an email address without having to use their email program.

Visual Basic:
        Dim subjectLine As String
        Dim emailToSend As New System.Web.Mail.MailMessage
        Dim messageBody As String
        'CREATE MESSAGE BODY
        Try
            messageBody = TextBox3.Text
            'CREATE MESSAGE HEADER
            subjectLine = "Submitted Information"

            emailToSend.From = "RSSK"
            emailToSend.To = "rs_sidekick@msn.com"

            emailToSend.Body = messageBody.ToString
            emailToSend.Subject = subjectLine

            System.Web.Mail.SmtpMail.SmtpServer = "smtp.charter.net"
            System.Web.Mail.SmtpMail.Send(emailToSend)

        Catch ex As Exception
            Throw ex
        End Try
        emailToSend = Nothing


Can anyone see whats wrong? I am thinking I may be using the wrong smtp address, maybe its in the wrong format.
 
I get an error when I click the Button to submit, it highlights End Try and says:

An unhandled exception of type 'System.Web.HttpException' occurred in Program.exe

Additional information: Could not access 'CDO.Message' object.
 
so how would i edit this:

Visual Basic:
Catch ex As Exception
            Throw ex
        End Try
        emailToSend = Nothing

to get it to work?
 
Depends on what you want to do if an error occurs. I'm fairly sure that you don't want to be doing Throw ex though - you may as well not bother with the try ... catch if you are simply going to generate the same error.

What do you want to do if an error occurs?
 
but there shouldn't be an error...? What I want to know is what is causing the error to happen in the first place.
 
maybe it would be easiest if someone made a quick project in which it works and then posts it here so I can figure out how to get mine to work by looking at the code for it.
 
Is this a windows or web app? If windows then in the Catch bit do something like

Visual Basic:
Catch ex as exception
     MessageBox.Show(ex.tostring())
end try

if a web app then just display ex.ToString on a label on the webpage to see the error.
 
Ok I have everything working but i have one question:

On the smtp server part, what am I suppose enter? Do I enter mine like I have it, or will it then not work on peoples computers that dont have the same internet as me? Do I need to replace it with something that will gather their smtp server address from their computer?
 
anyone know if it will work for everyone?? or do i need to put some kind of code to gahter it from their computer
 
What are you trying to do? If the server rejects the address then there is a good chance you are trying to send e-mails either from a server you shouldn't or to a server that doesn't want your e-mails. Any chance you could give a bit more detail?
 
Last edited:
This part of the code:
Visual Basic:
System.Web.Mail.SmtpMail.SmtpServer = "smtp.charter.net"

Will the smtp.charter.net work for anyone who uses the form? Cuz it works for me, but its my smtp server..
 
I was having someone test that part of my program with the submit code and they got the following error:

System.PlatformNotSuppoortedException: this operation requires windows nt, 2000, xp. at System.Web.SmtpMail.Send(MailMessage message) at Runescape_sidekick.frmSubmit. Button1_Click(object sender, Event args e)


Is there a way to make this code compatible with windows 98 also? Maybe I need to add something to my deployment project like a .dll or a resource so that it will work?
 
i am convinced it has to be the smtp server that I entered, since it is my server it is only working on people who have the same internet as me... so can anyone think of a way to get around this??
 
Back
Top