Lanc1988 Posted February 16, 2004 Posted February 16, 2004 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. Quote
mocella Posted February 16, 2004 Posted February 16, 2004 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 Quote
Lanc1988 Posted February 16, 2004 Author Posted February 16, 2004 so where do i put all of that code? all in the Submit button? Quote
Lanc1988 Posted February 17, 2004 Author Posted February 17, 2004 (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 February 17, 2004 by Lanc1988 Quote
Lanc1988 Posted February 17, 2004 Author Posted February 17, 2004 anyone know why im getting that error and how to fix it? Quote
mocella Posted February 17, 2004 Posted February 17, 2004 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. Quote
Heiko Posted February 17, 2004 Posted February 17, 2004 You probably need to add a reference to CDO Quote .nerd
mocella Posted February 17, 2004 Posted February 17, 2004 I only had to add a reference to System.Web, but I'd imagine he's already done that to even compile. Quote
Lanc1988 Posted February 17, 2004 Author Posted February 17, 2004 well, im not very advanced with working with email forms like these, so i probably haven't done that reference thing yet.. Quote
mocella Posted February 18, 2004 Posted February 18, 2004 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. Quote
Lanc1988 Posted February 18, 2004 Author Posted February 18, 2004 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. Quote
Lanc1988 Posted February 18, 2004 Author Posted February 18, 2004 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) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.