Use jmail to send emails in projects

Source: Internet
Author: User

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
    1. // Click send email
    2. Protected void btntransmit_click (Object sender, eventargs E)
    3. {
    4. Try
    5. {
    6. // Call the email sending Method
    7. Sendemail (txtsender. Text, txtsendername. Text, txttransmitname. Text, txttransmitpassword. Text, txtreceiver. Text, txtsubject. Text, txtcontent. Text, txtserver. Text );
    8. }
    9. Catch (exception ex)
    10. {
    11. Response. Write (ex. Message );
    12. }
    13. }
    14. /// <Summary>
    15. /// Use jmail to send an email
    16. /// </Summary>
    17. /// <Param name = "sender"> sender's email </param>
    18. /// <Param name = "sendername"> sender name </param>
    19. /// <Param name = "transmitname"> Login Name of the email sender's email address </param>
    20. /// <Param name = "transmitpassword"> sender's email password </param>
    21. /// <Param name = "recipient"> recipient's address </param>
    22. /// <Param name = "subject"> subject of the email </param>
    23. /// <Param name = "content"> email content </param>
    24. /// <Param name = "serverhost"> server address </param>
    25. Private void sendemail (string sender, string sendername, string transmitname, string transmitpassword, string receiver, string subject, string content, string serverhost)
    26. {
    27. // Create a jmail object
    28. Messageclass jmessage = new messageclass ();
    29. // Set the Encoding
    30. Jmessage. charset = "gb2312 ";
    31. // Set the mail header not to use the ISO-8859-1 Encoding
    32. Jmessage. isoencodeheaders = false;
    33. // Set the email address of the sent Email
    34. Jmessage. From = sender;
    35. // Set the sender name
    36. Jmessage. fromname = sendername;
    37. // Set the topic
    38. Jmessage. Subject = subject;
    39. // Set the email address or email server login name
    40. Jmessage. mailserverusername = transmitname;
    41. // Set the email address or email server password
    42. Jmessage. mailserverpassword = transmitpassword;
    43. // Add the email address for receiving the email
    44. Jmessage. addrecipient (receiver ,"","");
    45. // Set the body of the sent Email
    46. Jmessage. Body = content;
    47. // Determine whether the upload control is empty
    48. If (fluattachment. hasfile)
    49. {
    50. String filename = fluattachment. postedfile. filename;
    51. // Add an attachment
    52. Jmessage. addattachment (filename, true ,"");
    53. }
    54. // Send an email
    55. If (jmessage. Send (serverhost, false ))
    56. {
    57. Response. Write ("<SCRIPT> alert ('sent successfully! '); </SCRIPT> ");
    58. }
    59. Else
    60. {
    61. Response. Write ("<SCRIPT> alert ('sending failed! '); </SCRIPT> ");
    62. }
    63. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.