Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I really need a form that will submit info using email.

 

Like it would have a text box where they could enter their email then another for them to enter their name and then a text box where they could enter a message.

 

Then they could click a button (submit) and it would send it to a specified email address.

 

 

I dont need anything really fancy, i just need something basic.

Posted

Try this:

Imports System.Web.Mail

private sub SendAMessage()

Dim subjectLine As String
       Dim emailToSend As New MailMessage
       Dim messageBody As String

       'CREATE MESSAGE BODY
       Try
           messageBody = txtMessage.Text

           'CREATE MESSAGE HEADER
           subjectLine = "I sent this email from a WinForms App."

           emailToSend.From = "TextAccount"
           emailToSend.To = txtEmailTo.Text

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

           SmtpMail.SmtpServer = "yourSmtpServerAddress"
           SmtpMail.Send(emailToSend)

       Catch ex As Exception
           Throw ex
       End Try
       emailToSend = Nothing
end sub

Posted (edited)

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

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 = "TextAccount"

emailToSend.To = "rs_sidekick@msn.com.Text"

 

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

End Sub

 

 

 

------------------------------------------------

I have all of that in the Button's code and then when i run the program in 'debug' mode and click the button to send it, it says it cannot access 'CDO.Message' Object and then highlights "End Try" in yellow

Edited by Lanc1988
Posted

I'm not sure if any of this matters, but I'm running VS2002/2003 Enterprise Architect and also have Outlook 2002 installed on my development machine. My smtp server was a local domain Exchange server. Before I posted that code yesterday, I successfully sent my message.

 

Perhaps your smtp server requires credentials to be specified?

 

Which line was it that caused the exception, and perhaps if you could post the exception text I can see what's happening better.

Posted

In Solution Explorer, under your project, there's a folder called References. Right-click this, select "Add Reference" and in the first tab (.Net Assemblies), scroll to System.Web and select it.

 

Once you have that done you should be able to compile and run your code.

Posted

Ok, its still having an error when i click submit, it says "An unhandgled exception of type 'System.Web.HttpException' occurred in PROGRAM.exe

 

Additional information: Could not access 'CDO.Message' object.

 

 

 

Then it highlights "END TRY" in the code in yellow.

Posted
any ideas how to fix this? also, once this form does start working, anyone from anywhere that is connected to the internet will be able to submit the form right? (asking because i had to put my smtp address in part of the code)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...