Solved

ASP.Net Question: How do I use ASPEmail in a Namespace?

Posted on 2003-11-20
14
1,522 Views
Last Modified: 2013-11-25
Here's my problem. I hope I can describe it well.

I want to build single function/class which sends email that I can use in many different locations. I wish to make use of Persits ASPEmail which is free. The email component comes in a DLL and they have provided a "wrapper assembly".

According to the documentation:
<blockquote>AspEmail comes with an ASP.NET wrapper assembly, ASPEMAILLib.dll, which has to be placed in the \Bin subdirectory of your ASP.NET application. Alternatively, you can place this file in the Global Assembly Cache. </blockquote>

I am trying to build a .DLL module (my own namespace) using the VBC to compile it. In that module I declare a Namespace and in the namespace I declare a Class. In that Class I want to declare a public function which uses the ASPEmail component.

That way in my code I can write:

<%@ Import Namespace="MyNameSpace.Email" %>
(with MyNameSpace.dll in the /bin directory)

Then I can add in a call to: MyNameSpace.Email.SendEmail("user@somewhere.com",...)

Can anyone point me in the right direction on how to go about doing this?

Is this the wrong way to structure such a beast?
0
Comment
Question by:Iguanasan
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9793651
Iguanasan,
To get it work, you need to put your dll file inside \Bin (create it by yourself if not exists before) under your root application folder. Then, you need to import the namespace inside your application page. After that, you need to create an instance of the related Class as you need to use. Last, you can get it work with your pre-defind function build inside your dll.
eg:
<%I@ Import Namespace="MyNameSpace.Email"%>
Dim objEmail as new Email 'your classes
objEmail.SendEmail("user@somewhere.com",...)  '<--------your Sub function

Hope that's clear to you.

Regards
x_com
0
 
LVL 4

Author Comment

by:Iguanasan
ID: 9796562
That part is clear.  The problem is that I can't get that far.  I can't compile my DLL as I do not understand how to reference the ASPEmail component within my code in order to build my DLL.  When I compile I get this message:

: error BC30466: Namespace or type 'ASPEMAILLib' for the Imports 'ASPEMAILLib' cannot be found.

Here's the code I'm trying to compile:

Imports ASPEMAILLib
Namespace MyNameSpace
     Public Class Email
          Public Function SendEmail(ByRef strFrom, ByRef strFromName, ByRef strTo, ByRef strToName, ByRef strSubject, ByRef strMessage, ByRef strAttachments, ByRef bolHTML, ByRef strSMTPMailer)
          ' This function sends an email
          DIM Mailer as New Persits.MailSender
          ' I've also tried this and get errors on the "Server" not being declared.
          'Mailer = Server.CreateObject("Persits.MailSender")
...
          End Function
     End Class
End Namespace
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9799312
How did you "place this file in the Global Assembly Cache"?
0
 
LVL 4

Author Comment

by:Iguanasan
ID: 9799346
Ahh, well, there's the "rub", maybe.

1) Start.. Control Panel.. Microsoft .Net Framwork 1.1 Configuration.. Manage the Assembly Cache... Add an Assembly to the Cache...

2) Point to the ASPEMAILLib.dll supplied by Persits Software

3) Error: "Unable to add the selected assembly.  The assembly must have a strong name (name, version and public key).

So, I thought.  Hmmm.  Can't seem to add it to the GAC, so can I explicitly point to it in some other fashion.  Besides, I don't want to have to manage the GAC on the production web server when I upload this (if I don't have to).

Regards, Iguanasan
0
 
LVL 4

Assisted Solution

by:krznpsk
krznpsk earned 100 total points
ID: 9800121
"Imports" is not a valid way to Reference another assembly.  "Imports" merely creates a typing shortcut to the assembly, AFTER you have referenced it.

In your .vbproj or .csproj file, you need to add a reference tag.  This is what a reference tag looks like:

<Reference
    Name = "Library_Data"
    Project = "{1B208C9F-F632-41FC-A0F0-A41B762B1AE3}"
    Package = "{F184B08F-C81C-45F6-A57F-5ABD9991F28F}"
/>  

The "Project" attribute is referring to the ProjectGuid of the assembly you're referencing.  You will find that in the .vbproj or .csproj of the project that you used to compile it.

I'm not sure what the Package attribute is...

You might be able to get away with skipping the Project and Package attributes in this tag... I honestly don't know.  I am assuming that you're not using Visual Studio, because that would make things A LOT easier.  My theory is that if you don't have those two attributes, the compiler will look for your dll in a downward path from your project root dir... like, .\, then .\bin, etc.

It's tricky, but this is how you need to add a reference, for when you compile the .dll you will eventually need to build the ASP.NET assembly.

I hope this gets you going in the right direction -- good luck!
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9800562
There is a program, GACUTIL, that can handle the necessary references to put an assembly in the cache.
0
 
LVL 6

Accepted Solution

by:
zrh earned 400 total points
ID: 9801271
You can use the command line switch also, I believe its /r:ASPEMAILLib.dll, let me check though.
ZRH
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Expert Comment

by:zrh
ID: 9801276
Yeah, thats it
Hope that helps,
ZRH
0
 
LVL 4

Author Comment

by:Iguanasan
ID: 9801346
Wahoo!  Got it working.  I'll explain in my next post how along with assigning points.  I gotta run at the moment...
0
 
LVL 4

Author Comment

by:Iguanasan
ID: 9801402
Imports was wrong.  Took that out, thanks krznpsk.  Then I used the /r: switch on the command line vbc command, thanks zrh, and tinkered a little bit more and voila!  It worked.

Here's the result:

Namespace MyNameSpace
     Public Class Email
          Public Function SendEmail(ByRef strFrom, ByRef strFromName, ByRef strTo, ByRef strToName, ByRef strSubject, ByRef strMessage, ByRef strAttachments, ByRef bolHTML, ByRef strSMTPMailer)
          ' This function sends an email
          DIM Mailer as New ASPEMAILLib.MailSender
          ...
          End Function
    End Class
End Namespace

My vbc command was like this:

c:\vbc /t:library /out:MyNameSpace.dll MyNameSpace.vb /r:ASPEMAILLib.dll

Then I put both MyNameSpace.dll and ASPEMAILLib.dll in the /bin directory.

Then in my ASPX code I put:

<%@ Page Language="VB" %>
<%@ Import Namespace="MyNameSpace" %>
<%@ Import Namespace="System.Data" %>
<script language="vb" runat="Server">
Sub Page_Load(Sender as Object, E as EventArgs)
   Dim MyObj as New MyNameSpace.Email
   MyObj.SendEmail(parameter list)
End Sub
</script>

Regards, Iguanasan
0
 
LVL 6

Expert Comment

by:zrh
ID: 9802766
FYI krznpsk:
  The package attribute has to do with the project system being used,
  more info: http://www.vsipdev.com

FYI Iguanasan:
  The imports directive could still be used if you want:
  Imports ASPEMAILLib; 'assuming this is actually the namespace
  Namespace MyNameSpace
       Public Class Email
            Public Function SendEmail(ByRef strFrom, ByRef strFromName, ByRef strTo, ByRef strToName, ByRef strSubject, ByRef strMessage, ByRef strAttachments, ByRef bolHTML, ByRef strSMTPMailer)
            ' This function sends an email
            DIM Mailer as New MailSender ' assuming this is a class under said namespace
            ...
            End Function
      End Class
  End Namespace

ZRH
0
 
LVL 4

Author Comment

by:Iguanasan
ID: 9802773
zrh, Thanks for the follow up.  I'll remember it for next time.  Since it worked without it I assumed it should not have been there.

Iguanasan
0
 
LVL 6

Expert Comment

by:zrh
ID: 9802819
No problem. It isn't necessary, but if you had to refer to it alot the imports directive would allow you to refer to the class with out it having to be fully qualified (less typing).  I just thought I would tell you that it isn't necessarily incorrect to have the imports directive, you just have to have a reference to the assembly also. Or else it doesn't know where to look for the namespace.

ZRH
0
 
LVL 4

Author Comment

by:Iguanasan
ID: 9868411
Sorry.  Been really busy and forgot to come back to it.  Thanks again for all your help, people!

Regards, Iguanasan
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now