Jan 17th, 2013, 06:46 PM
sending email from contact page of website
i have been trying to figure out how to send an email message from user input on a contact page of my website, and am using visual studio 2010. ideally, the user would input their name, email address, phone number, and a short description in text boxes on a contact page, and when they click the submit button, it generates an email message to me. i have been reading and trying various things for two days now, and have finally gotten the code right, but when i publish the website, i get the following build errors: 'MailMessage.From' is not accessible in this context because it is 'Friend' and one for MailMessage.To, MailMessage.Subject, MailMessage.Body and SMTPClient.Credentials all saying the same thing. the code i have is
Partial Class contact
Dim mMailSettings As System.Net.Configuration.MailSettingsSectionGroup
Dim mPort As Integer = mMailSettings.Smtp.Network.Port
Dim mHost As String = mMailSettings.Smtp.Network.Host
Dim mPassword As String = mMailSettings.Smtp.Network.Password
Dim mUsername As String = mMailSettings.Smtp.Network.UserName
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("%TextBox3%")
'set the content
mail.Subject = "contact"
mail.Body = "%TextBox4%"
'send the message
Dim smtp As New SmtpClient("relay-hosting.secureserver.net")
'to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = NetworkCredential("myusername", "password")
End Sub 'Authenticate
Private Function NetworkCredential(ByVal p1 As String, ByVal p2 As String) As Object
Throw New NotImplementedException
i thought that the 'Friend' part of the error meant that i was not able to create an instance directly, it had to be done and sent back. that's what i'm reading anyway, i am new to this. any help is appreciated
Last edited by sfzombie13; Jan 17th, 2013 at 06:47 PM.
Reason: error in code posted
< advertising link removed by moderator >
Click Here to Expand Forum to Full Width
Survey posted by VBForums.