473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

System.Web.Mail.MailMessage in class

Hi,

I have created a class that is totally seperate from my web application.
However this class is used extensivly by the web application for stuff like
data access.
I wish to add a function to this class that will send email, however my
class will not seem to recognise the
system.web.mail.mailmessage.

my first impression on this is that I may have to use some sort of third
part mail component to send mail from inside my class,
however I am baffled why the class will not recognise the
system.web.mail.mailmessage namespace

The code that I normally use to send mail is listed below, this does not
work from inside my class

Dim Message As System.Web.Mail.MailMessage = New
System.Web.Mail.MailMessage
Dim SmtpMail As System.Web.Mail.SmtpMail
Message.To = strEmailAddress
Message.From = txtFrom.Text
Trace.Warn("FROM ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailText

Message.BodyFormat = Mail.MailFormat.Html

SmtpMail.SmtpServer = "saturn"

SmtpMail.Send(Message)

any help is greatly appreciated

cheers

martin.
Nov 18 '05 #1
5 2205
> I have created a class that is totally seperate from my web application.
I assume this is in a seperate Class Library project?
If so, you'll need to add a reference to the System.Web library to your
Class Library project.

HTH,

Morgan

"martin" <ma***************@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have created a class that is totally seperate from my web application. However this class is used extensivly by the web application for stuff like data access.
I wish to add a function to this class that will send email, however my
class will not seem to recognise the
system.web.mail.mailmessage.

my first impression on this is that I may have to use some sort of third
part mail component to send mail from inside my class,
however I am baffled why the class will not recognise the
system.web.mail.mailmessage namespace

The code that I normally use to send mail is listed below, this does not
work from inside my class

Dim Message As System.Web.Mail.MailMessage = New
System.Web.Mail.MailMessage
Dim SmtpMail As System.Web.Mail.SmtpMail
Message.To = strEmailAddress
Message.From = txtFrom.Text
Trace.Warn("FROM ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailText

Message.BodyFormat = Mail.MailFormat.Html

SmtpMail.SmtpServer = "saturn"

SmtpMail.Send(Message)

any help is greatly appreciated

cheers

martin.

Nov 18 '05 #2
Hi,

Maybe I wasn't clear enough in my orignal post.
The new class library will not let me make a referenece to
system.web.mail.mailmessage
it will let me make a reference to
system.web
but this is no good to me, as I want access to the "Mail" part of the
namespace.
It would appear that most of the system.web namespace is only availible from
a web application.

The only system.web namespaces that are availible to import in my class are

Imports System.Web.AspNetHostingPermission
Imports System.Web.AspNetHostingPermissionAttribute
Imports System.Web.AspNetHostingPermissionLevel

This is my whole problem,
if I cant import the namespace how can I use the classes.
I have tried making a fully qualified refernece to the object but that will
not work either.

I would appreciate any thoughts.

cheers

martin.



"Morgan" <za**********@primposta.com> wrote in message
news:uM****************@TK2MSFTNGP12.phx.gbl...
I have created a class that is totally seperate from my web application.

I assume this is in a seperate Class Library project?
If so, you'll need to add a reference to the System.Web library to your
Class Library project.

HTH,

Morgan

"martin" <ma***************@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have created a class that is totally seperate from my web

application.
However this class is used extensivly by the web application for stuff

like
data access.
I wish to add a function to this class that will send email, however my
class will not seem to recognise the
system.web.mail.mailmessage.

my first impression on this is that I may have to use some sort of third
part mail component to send mail from inside my class,
however I am baffled why the class will not recognise the
system.web.mail.mailmessage namespace

The code that I normally use to send mail is listed below, this does not
work from inside my class

Dim Message As System.Web.Mail.MailMessage = New
System.Web.Mail.MailMessage
Dim SmtpMail As System.Web.Mail.SmtpMail
Message.To = strEmailAddress
Message.From = txtFrom.Text
Trace.Warn("FROM ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailText

Message.BodyFormat = Mail.MailFormat.Html

SmtpMail.SmtpServer = "saturn"

SmtpMail.Send(Message)

any help is greatly appreciated

cheers

martin.


Nov 18 '05 #3
You cannot reference system.web.mail.mailmessage, as it is a member of the
System.Web library, you can only create an instance of the object
mailmessage

I don't know what you're working with, but try this for starters...
<assuming VB.Net>
1. Create a new ClassLibrary project
2. Right click on the "References" folder in the Solution Explorer and "Add
Reference"
3. Select System.Web from the .Net tab.
4. In the Class1.vb file, paste this code:

Imports System.Web

Public Class Class1

Private Sub SendMessage()

Dim msg As New System.Web.Mail.MailMessage()

With msg

End With

End Sub

End Class

No errors when I build. Seems you've got something going on in your project
that isn't allowing access to the root system.web library.

--Morgan
"martin" <ma***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

Maybe I wasn't clear enough in my orignal post.
The new class library will not let me make a referenece to
system.web.mail.mailmessage
it will let me make a reference to
system.web
but this is no good to me, as I want access to the "Mail" part of the
namespace.
It would appear that most of the system.web namespace is only availible from a web application.

The only system.web namespaces that are availible to import in my class are
Imports System.Web.AspNetHostingPermission
Imports System.Web.AspNetHostingPermissionAttribute
Imports System.Web.AspNetHostingPermissionLevel

This is my whole problem,
if I cant import the namespace how can I use the classes.
I have tried making a fully qualified refernece to the object but that will not work either.

I would appreciate any thoughts.

cheers

martin.



"Morgan" <za**********@primposta.com> wrote in message
news:uM****************@TK2MSFTNGP12.phx.gbl...
I have created a class that is totally seperate from my web application.
I assume this is in a seperate Class Library project?
If so, you'll need to add a reference to the System.Web library to your
Class Library project.

HTH,

Morgan

"martin" <ma***************@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have created a class that is totally seperate from my web

application.
However this class is used extensivly by the web application for stuff

like
data access.
I wish to add a function to this class that will send email, however

my class will not seem to recognise the
system.web.mail.mailmessage.

my first impression on this is that I may have to use some sort of third part mail component to send mail from inside my class,
however I am baffled why the class will not recognise the
system.web.mail.mailmessage namespace

The code that I normally use to send mail is listed below, this does not work from inside my class

Dim Message As System.Web.Mail.MailMessage = New
System.Web.Mail.MailMessage
Dim SmtpMail As System.Web.Mail.SmtpMail
Message.To = strEmailAddress
Message.From = txtFrom.Text
Trace.Warn("FROM ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailText

Message.BodyFormat = Mail.MailFormat.Html

SmtpMail.SmtpServer = "saturn"

SmtpMail.Send(Message)

any help is greatly appreciated

cheers

martin.



Nov 18 '05 #4
Hi Morgan,

thnaks for you help. the thing that I was missing was not adding a
referenece in my project.

I thought simply writing

imports system.web at the top of the vb file would do the trick.

seems it won't and I have to add the refernce.

anyway, everything works perfectly now so thanks.

cheers

martin.

"Morgan" <za**********@primposta.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl...
You cannot reference system.web.mail.mailmessage, as it is a member of the
System.Web library, you can only create an instance of the object
mailmessage

I don't know what you're working with, but try this for starters...
<assuming VB.Net>
1. Create a new ClassLibrary project
2. Right click on the "References" folder in the Solution Explorer and "Add Reference"
3. Select System.Web from the .Net tab.
4. In the Class1.vb file, paste this code:

Imports System.Web

Public Class Class1

Private Sub SendMessage()

Dim msg As New System.Web.Mail.MailMessage()

With msg

End With

End Sub

End Class

No errors when I build. Seems you've got something going on in your project that isn't allowing access to the root system.web library.

--Morgan
"martin" <ma***************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

Maybe I wasn't clear enough in my orignal post.
The new class library will not let me make a referenece to
system.web.mail.mailmessage
it will let me make a reference to
system.web
but this is no good to me, as I want access to the "Mail" part of the
namespace.
It would appear that most of the system.web namespace is only availible

from
a web application.

The only system.web namespaces that are availible to import in my class

are

Imports System.Web.AspNetHostingPermission
Imports System.Web.AspNetHostingPermissionAttribute
Imports System.Web.AspNetHostingPermissionLevel

This is my whole problem,
if I cant import the namespace how can I use the classes.
I have tried making a fully qualified refernece to the object but that

will
not work either.

I would appreciate any thoughts.

cheers

martin.



"Morgan" <za**********@primposta.com> wrote in message
news:uM****************@TK2MSFTNGP12.phx.gbl...
> I have created a class that is totally seperate from my web application. I assume this is in a seperate Class Library project?
If so, you'll need to add a reference to the System.Web library to your Class Library project.

HTH,

Morgan

"martin" <ma***************@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I have created a class that is totally seperate from my web
application.
> However this class is used extensivly by the web application for stuff like
> data access.
> I wish to add a function to this class that will send email, however my > class will not seem to recognise the
> system.web.mail.mailmessage.
>
> my first impression on this is that I may have to use some sort of third > part mail component to send mail from inside my class,
> however I am baffled why the class will not recognise the
> system.web.mail.mailmessage namespace
>
> The code that I normally use to send mail is listed below, this does not > work from inside my class
>
> Dim Message As System.Web.Mail.MailMessage = New
> System.Web.Mail.MailMessage
> Dim SmtpMail As System.Web.Mail.SmtpMail
> Message.To = strEmailAddress
> Message.From = txtFrom.Text
> Trace.Warn("FROM ADDRESS", txtFrom.Text)
> Message.Subject = txtSubject.Text
> Message.Body = strSendEmailText
>
> Message.BodyFormat = Mail.MailFormat.Html
>
> SmtpMail.SmtpServer = "saturn"
>
> SmtpMail.Send(Message)
>
> any help is greatly appreciated
>
> cheers
>
> martin.
>
>



Nov 18 '05 #5

"martin" <ma***************@hotmail.com> wrote in message
news:uu**************@TK2MSFTNGP12.phx.gbl...
Hi Morgan,

thnaks for you help. the thing that I was missing was not adding a
referenece in my project.

I thought simply writing

imports system.web at the top of the vb file would do the trick.

seems it won't and I have to add the refernce.

anyway, everything works perfectly now so thanks.

cheers

martin.


"Imports" in VB (and the equivalent "using" in C#) only make it easier to
write
the code: you don't have to type the complete namespace path if that is
already
mentioned in an Import/using clause.
Without an Import/using you can still access everything you have referenced,
but then you need to type the complete namespace.
As you found out, "referencing" is the important part.

Hans Kesting
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
1
by: maflatoun | last post by:
Hi everyone, I'm coverting some of our code here from the old way of send email in ..net 1.1 to the new .net 2.0. However, everyone I switch the code the new method there is a delay of 1-2...
0
by: howardr101 | last post by:
Hi, Have hunted around on the groups and can't find anything, hence. I've tried this against 2 mail servers (mailtraq and hmailserver) and it occus with both. The problems seems to be that...
2
by: Tim | last post by:
I am trying to send a simple mail message using windows forms in VB.NET 2005. When executing the code, I get a general 'Configuration system failed to initialize' error message when the code...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
6
by: Anthony P. | last post by:
Hello Everyone, I'm attempting to create a new MailMessage object by following a tutorial and I can't seem to get it right according to VS 2008. I'm hoping someone here can help me find out what...
2
by: Prefers Golfing | last post by:
We are having to extend the System.Net.Mail namespace and need some help with coding it. We have added several properties to System.Net.Mail.Attachment and need to add our several of them to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.