|
|
|
|
|
|
Using aspNetEmail in a COM Environment (ASP/VB)
|
|
(A sample archive of gacutil, regasm, and test files can be found here. See the included readme for more information.)
A number of customers have requested information using aspNetEmail in a COM environment, such as an ASP page. The following article will discuss
- Registering aspNetEmail for COM
- Using aspNetEmail in an ASP page
- Un-registering aspNetEmail
NOTE: Please note, although you can use aspNetEmail in a COM environment, we do not support that functionality. All of our R & D is devoted to future versions of .NET, and this paper is provided for those people that need to use aspNetEmail in COM environments.
If you understand the basics of registering a .NET assembly for COM, you can skip directly to the cookbook version.
Registering aspNetEmail for COM
Although you want to use aspNetEmail in a COM environment, the .NET framework will still be required to run on the server.
When a COM client wants to call a .NET
assembly, such as aspNetEmail, the COM client cannot directly access
the .NET assembly. Instead, the COM client must access a COM
Callable Wrapper, or more commonly known as a CCW. The CCW acts as a
proxy for the managed dll. For more information on CCWs, check out
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcomcallablewrapper.asp
To create a CCW two command line tools will be used, tlbexp.exe and regasm.exe.
tlbexp.exe
tlbexp.exe is used to export type library information used by aspNetEmail.
The command line syntax for tlbexp.exe will be
C:\>tlbexp aspNetEmail.dll
Running this command creates a type library named aspNetEmail.tlb.
regasm.exe
Once the type library information
has been exported, regasm.exe is used to register the assembly. The
command line syntax for regasm.exe is
C:\>regasm aspNetEmail.dll /tlb:aspNetEmail.tlb
For more information on tlbexp.exe and regasm.exe check out
tlbexp.exe http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrftypelibraryexportertlbexpexe.asp
regasm.exe http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfassemblyregistrationtoolregasmexe.asp
Now that aspNetEmail has been registered for use by COM clients, lets create an ASP page to use it.
Creating an ASP Page
Using your favorite editor, create a new ASP page, under IIS, named aspNetEmail_test.asp.
Add the following code
<%Option Explicit %>
<%
'if you are using aspNetEmail 3.x, the license file needs to be loaded
'before the EmailMessage object can be created. Simply uncomment the following 3 lines
'Dim lic
'Set lic = Server.CreateObject( "aspNetEmail.EmailLicense" )
'lic.LoadLicenseFile( "c:\aspNetEmail.xml.lic" ) 'set a valid path to the license file here.
Dim msg
Set msg = Server.CreateObject( "aspNetEmail.EmailMessage" )
msg.Server = "mail.mycompany.com"
msg.To = "me@mycompany.com"
msg.FromAddress = "you@yourcompany.com"
msg.Subject = "this is a test from an ASP page"
msg.Body = "this is the body of my message."
if msg.Send then
Response.Write( "Message Sent!" )
else
Response.Write( "Message was not sent" )
End If
%>
This code creates an EmailMessage object,
and sets the following properties: Server To From
Subject Body
And finally it sends the email.
Note: Be sure to set the proper "Server", "To", and "FromAddress" properties to match your environment.
That’s it, that’s all there is to using aspNetEmail from a COM Client. View the page in a browser, and an email will be to sent!
Un-registering aspNetEmail
If you ever need to un-register aspNetEmail, from COM
client use, you will again use the regasm.exe command line tool. The
syntax is
C:\>regasm /u aspNetEmail.dll
Conclusion
In this article we’ve seen how to register aspNetEmail for COM Client use. This is achieved by
1. Exporting type library information using tlbexp.exe
2. Registering aspNetEmail using regasm.exe
3. Creating an ASP page for testing.
Cookbook Version
If you understand the basics of registering a .NET assembly for COM, and simply want the cook-book version, those steps can be found below.
- Open a Visual Studio Command Prompt
- Navigate to the directory containing the aspNetEmail.dll, normally
C:\Program
Files\AdvancedIntellect\aspNetEmail\v2.5.0>
- execute
tlbexp
aspNetEmail.dll
- execute
regasm
aspNetEmail.dll /tlb:aspNetEmail.tlb
- Create an ASP page for testing, with the following code
<%Option Explicit %>
<%
'if you are using aspNetEmail 3.x, the license file needs to be loaded
'before the EmailMessage object can be created. Simply uncomment the following 3 lines
'Dim lic
'Set lic = Server.CreateObject( "aspNetEmail.EmailLicense" )
'lic.LoadLicenseFile( "c:\aspNetEmail.xml.lic" ) 'set a valid path to the license file here.
Dim msg
Set msg = Server.CreateObject( "aspNetEmail.EmailMessage" )
msg.Server = "mail.mycompany.com"
msg.To = "me@mycompany.com"
msg.FromAddress = "you@yourcompany.com"
msg.Subject = "this is a test from an ASP page"
msg.Body = "this is the body of my message."
if msg.Send then
Response.Write( "Message Sent!" )
else
Response.Write( "Message was not sent" )
End If
%>
A screen shot of the command prompt can be found below.
|