Home>Network programming tutorial>ASP tutorial

asp calls a DLL written in C# to send emails

Author:Eve Cole Update Time:2009-06-23 17:00:02

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:

  1. <%
  2. dim send
  3. set send = Server.CreateObject( "IMELS.SendMail" )
  4.   
  5. send.From = "[email protected]"   
  6. send.FromName = "无question"   
  7. send.Smtp = "smtp.163.com"   
  8. send.Username = "Username"   
  9. send.Password = "Password"   
  10. send.Subject = "asp calls the DLL written in C# to send the email test title"   
  11. send.ContentType = "html"   
  12. send.Charset = "gb2312"   
  13. send.Body = "asp calls the DLL written in C# to send the email test body"   
  14. send. To = "[email protected]"   
  15. send.CC = "CC address"   
  16. send.BCC = "Bcc address"   
  17. send.Send()
  18. Response.Write( send.Error )
  19. %>

Okay, you're done! !