I have always wanted to write a server component that can send emails using ASP, but using VC is too troublesome and I have never been able to do it.
I read an article two days ago about how ASP can call a DLL written in C#. I tried it and it worked. I'm very happy. Now it's easier to write something to send emails.
Haha, it’s very simple. It’ll be done in a moment. I don’t dare to keep it to myself. Let’s take a look at the code first:
Let’s talk about the specific implementation process:
1. First create a new class library project; open the project property page, set the assembly name to "IMELS" on the "Application" tab (of course, you can set this to a name you like), and the output type is class library, as shown in the figure :
Click "Assembly Information" and check "Make assembly COM visible", as shown in the figure:
2. On the "Signature" tab, check "Sign the program", as shown in the figure:
Then select the key file in the "Select strong name key file" drop-down list. If there is no key file, select "New". Here I select New, as shown in the figure:
Enter the name of the key in the "Key file name" field. You can choose to add a password to the key to protect it. I did not use a password here.
Then add a class "SendMail" to the project, and the code is as above.
3. After the code is completed, generate the DLL file and put the DLL on the D: disk or other disk, but it is best not to put it on the system disk, and then register it. You cannot use regsvr32 to register a DLL written in C#. You must use regsvr32. regasm, the format is: regasm /codebase d:DLLIMELS.dll.
In this way, the writing and registration of the DLL have been completed. The following is the application. The calling method in asp is as follows:
Okay, you're done! !