Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error message when creating e-mail instance

Status
Not open for further replies.

peebman2000

Programmer
Nov 28, 2006
30
US
Hello everyone, if you are familar with my username Peebman2000, i'm a beginner programmer with alot of questions. Anyway below is my code to send emails with an attachment. Where I declare "mailmsg as new mailmessage(textemail.text, toaddress)", i'm getting an error message of "type 'MailMessage' is not defined". Its defined and I don't know why I'm getting this message. Does anyone know why and have a suggestion on how I can get it right? Thanks.


Imports System
Imports System.IO
Imports System.Text
Imports System.Threading

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tsmtpserver As String
tsmtpserver = "smtp.odn.state.oh.us"
Dim space As String = " "
Dim toaddress As String = textemail.Text
'mystring = textemail.Text
'lblemail.Text = mystring
Dim mailmsg As New MailMessage(textemail.Text, toaddress)
'Dim mailmsg As New System.Net.Mail.MailMessage

'Dim attachname As String
'mailmsg.From = textemail.Text

'mailmsg.To.add(textemail.Text, "")
'mailmsg.fromaddress = "david.peebles@das.state.oh.us"
'mailmsg.fromname = "david"
'mailmsg.bodytext = "this is a test dummy, Notre Dame are losers"
'mailmsg.subject = "test"

mailmsg.textfirst.text += "My First Name:" + space + space + textfirst.Text
mailmsg.textlast.text += "My Last Name:" + space + space + textlast.Text

If Not (FileUpload1.PostedFile Is Nothing) And FileUpload1.PostedFile.FileName <> "" Then
Dim fileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
mailmsg.Attachments.Add(FileUpload1.PostedFile.InputStream, fileName)
End If


End Sub
Private Function GetDomain(ByVal email As String) As String
Dim index = email.IndexOf("@")
Return email.Substring(index + 1)
End Function


End Class
 
Try using System.Web.Mail.MailMessage



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
I tried and 'dim mailmsg as new mailmessage()' still gives and error of mailmessage is not defined. Any other suggestions?
 
Dim mailmsg As New [red]System.Web.Mail.[/red]MailMessage()

mailmsg.Body = "this is a test dummy, Notre Dame are losers"

(BTW, did you hear that Notre Dame just made college football history by becoming the first team ever to lose nine consecutive bowl games?)

mailmsg.To = toaddress

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Okay I tried and it gives an error saying System.web.mail.mailmessage is obsolet: the recommended alternative is system.net.mail.mailmessage. My form is in VS2005, I just don't understand it. FYI i'm importing system.web.mail and system.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top