1. Add the jmail component. In Solution Explorer of Vs, right-click Add reference, select Browse, and select the jmail. dll file. The added jmail component is displayed in the bin folder.
2. register the jmail component: start --> Run --> input: regsvr32 D: \ DOTNET plug-in and script \ jmail. dll
Regsvr32 explanation:
This command line tool registers the DLL file as a command in the registry.
Syntax
Regsvr32 [/u] [/S] [/n] [/I [: Invalid line] dllname
Parameters
/U
The server is not registered.
/S
The specified regsvr32 runs quietly without any message boxes.
/N
Specify not to call the dllregisterserver. This option must be used with/I.
/I: using line
Call dllinstall to pass it to the optional pipeline line ]. When used together with/u, it calls DLL uninstallation.
Dllname
Specifies the DLL file name to be registered.
/?
Display help at the command prompt.
After completing 1 or 2 operations, let's write the code:
Interface reference:
C # code
- // Click send email
- Protected void btntransmit_click (Object sender, eventargs E)
- {
- Try
- {
- // Call the email sending Method
- Sendemail (txtsender. Text, txtsendername. Text, txttransmitname. Text, txttransmitpassword. Text, txtreceiver. Text, txtsubject. Text, txtcontent. Text, txtserver. Text );
- }
- Catch (exception ex)
- {
- Response. Write (ex. Message );
- }
- }
- /// <Summary>
- /// Use jmail to send an email
- /// </Summary>
- /// <Param name = "sender"> sender's email </param>
- /// <Param name = "sendername"> sender name </param>
- /// <Param name = "transmitname"> Login Name of the email sender's email address </param>
- /// <Param name = "transmitpassword"> sender's email password </param>
- /// <Param name = "recipient"> recipient's address </param>
- /// <Param name = "subject"> subject of the email </param>
- /// <Param name = "content"> email content </param>
- /// <Param name = "serverhost"> server address </param>
- Private void sendemail (string sender, string sendername, string transmitname, string transmitpassword, string receiver, string subject, string content, string serverhost)
- {
- // Create a jmail object
- Messageclass jmessage = new messageclass ();
- // Set the Encoding
- Jmessage. charset = "gb2312 ";
- // Set the mail header not to use the ISO-8859-1 Encoding
- Jmessage. isoencodeheaders = false;
- // Set the email address of the sent Email
- Jmessage. From = sender;
- // Set the sender name
- Jmessage. fromname = sendername;
- // Set the topic
- Jmessage. Subject = subject;
- // Set the email address or email server login name
- Jmessage. mailserverusername = transmitname;
- // Set the email address or email server password
- Jmessage. mailserverpassword = transmitpassword;
- // Add the email address for receiving the email
- Jmessage. addrecipient (receiver ,"","");
- // Set the body of the sent Email
- Jmessage. Body = content;
- // Determine whether the upload control is empty
- If (fluattachment. hasfile)
- {
- String filename = fluattachment. postedfile. filename;
- // Add an attachment
- Jmessage. addattachment (filename, true ,"");
- }
- // Send an email
- If (jmessage. Send (serverhost, false ))
- {
- Response. Write ("<SCRIPT> alert ('sent successfully! '); </SCRIPT> ");
- }
- Else
- {
- Response. Write ("<SCRIPT> alert ('sending failed! '); </SCRIPT> ");
- }
- }