473,722 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("FRO M ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailTex t

Message.BodyFor mat = Mail.MailFormat .Html

SmtpMail.SmtpSe rver = "saturn"

SmtpMail.Send(M essage)

any help is greatly appreciated

cheers

martin.
Nov 18 '05 #1
5 2236
> 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******** ******@TK2MSFTN GP12.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("FRO M ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailTex t

Message.BodyFor mat = Mail.MailFormat .Html

SmtpMail.SmtpSe rver = "saturn"

SmtpMail.Send(M essage)

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.AspN etHostingPermis sion
Imports System.Web.AspN etHostingPermis sionAttribute
Imports System.Web.AspN etHostingPermis sionLevel

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**********@p rimposta.com> wrote in message
news:uM******** ********@TK2MSF TNGP12.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******** ******@TK2MSFTN GP12.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("FRO M ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailTex t

Message.BodyFor mat = Mail.MailFormat .Html

SmtpMail.SmtpSe rver = "saturn"

SmtpMail.Send(M essage)

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******** ********@TK2MSF TNGP12.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.AspN etHostingPermis sion
Imports System.Web.AspN etHostingPermis sionAttribute
Imports System.Web.AspN etHostingPermis sionLevel

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**********@p rimposta.com> wrote in message
news:uM******** ********@TK2MSF TNGP12.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******** ******@TK2MSFTN GP12.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("FRO M ADDRESS", txtFrom.Text)
Message.Subject = txtSubject.Text
Message.Body = strSendEmailTex t

Message.BodyFor mat = Mail.MailFormat .Html

SmtpMail.SmtpSe rver = "saturn"

SmtpMail.Send(M essage)

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**********@p rimposta.com> wrote in message
news:eT******** ******@TK2MSFTN GP11.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******** ********@TK2MSF TNGP12.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.AspN etHostingPermis sion
Imports System.Web.AspN etHostingPermis sionAttribute
Imports System.Web.AspN etHostingPermis sionLevel

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**********@p rimposta.com> wrote in message
news:uM******** ********@TK2MSF TNGP12.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******** ******@TK2MSFTN GP12.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("FRO M ADDRESS", txtFrom.Text)
> Message.Subject = txtSubject.Text
> Message.Body = strSendEmailTex t
>
> Message.BodyFor mat = Mail.MailFormat .Html
>
> SmtpMail.SmtpSe rver = "saturn"
>
> SmtpMail.Send(M essage)
>
> any help is greatly appreciated
>
> cheers
>
> martin.
>
>



Nov 18 '05 #5

"martin" <ma************ ***@hotmail.com > wrote in message
news:uu******** ******@TK2MSFTN GP12.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, "referencin g" 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
8671
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 spreadsheet attachment per message, seems to be causing som kind of corruption of the attachment, while several spreadsheets per works just fine. Consider the following three snippets of C# code:
1
8180
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 the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
2
3496
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 application, and also succeeds from the asp.net page with BodyFormat=MailFormat.Text. I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net Framework v1.1 SP1. The code worked fine under W2K SP4.
1
4181
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 minutes before an email is sent (this is on my local computer point to my local smtp -> localhost). Anyone knows what the problem could be? BTW my computer in located behind a firewall and I'm sending test emails to my gmail account and hotmail...
0
2408
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 when the SMTPClient attaches to the server and the server sends it greeting message, if anything other than +OK is received by the client it throws an exception and falls over.
2
4320
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 instatiates a new MailMessage object (see below) My form has the following code: Imports System.Net.Mail Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
2
17484
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 the bare minimum: System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("<my mail server IP>", 25); smtp.Send("<one of my email addresses>", "<another of my email addresses>", "Hello", "World");
6
3546
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 I am doing wrong. I would greatly appreciate it: First, I am importing the System.Net.Mail class like this: Imports System.Net.Mail
2
2384
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 System.Net.Mail.MailMessage.Attachments. // public AttachmentCollection Attachments { get; } How do we override AttachmentCollection to be a collection of OurNamespace.Attachments?
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.