Use JMail to send emails in the project, and use jmail to send emails in the project.

Source: Internet
Author: User

Use JMail to send emails in the project, and use jmail to send emails in the project.

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. }

How to automatically send emails using jmail in js

<Script>
Function SendEMail (){
Var jMail = new ActiveXObject ("Jmail. message ");

JMail. Silent = true;

JMail. Charset = "UTF-8 ";

JMail. FromName = "xx@xxx.com"; // sender
JMail. From = "xx@xxx.com"; // mail address of the sender
JMail. AddRecipient ("xxxxxx@qq.com"); // recipient's email address
JMail. Subject = "ceshi ";

JMail. Body = "asdf"; // Email content
JMail. MailServerUserName = "xx@xxx.com"; // username
JMail. MailServerPassWord = "cmswe888"; // password
Var ret = jMail. Send ("mail.xxx.com ");

Alert (ret );
JMail. Close ();

}

</Script>

<Input type = button onclick = SendEMail () value = send/>

Tested, can be sent...
Key points:
1 install JMAIL locally
2SMTP refers to the mailbox to open smtp ~

Discuz! How to Use Jmail to send emails

After Jmail is installed (Jmail. dll is actually registered), you can use programming languages such as vb, js, and C # To Call The JMail. Message object to send a mail.
The Jmail installation version contains complete manuals and examples. Here is an example of vbs.

First install Jmail, or download Jmail. dll and then run
Regsvr32 <path> Jmail. dll
<Path> is the path where you put jmail. dll.

Save the following content as *. vbs and double-click send

'Initialization object
Set msgJmail = CreateObject ("JMail. Message ")

'Make Jmail record logs for troubleshooting
MsgJmail. Logging = true

'Body code of the email
MsgJmail. Charset = "gb2312"

'Sender, which can be written at will theoretically
MsgJmail. From = "mailtest@gasgoo.com"

'Sender name, whatever you want
MsgJmail. FromName = "test"

'Add one recipient. Repeat this sentence to add multiple recipients.
MsgJmail. AddRecipient "test@163.com"

'Mail subject
MsgJmail. Subject = "test mail"

'Body of the email. Repeat this sentence to add multiple lines.
MsgJmail. AppendText "this is a test email"

'You can also use this sentence to read the content of a file and append it to the body.
'Msgjmail. Appendfromfile "d: \ mail.txt"

'Sending command, @ is followed by the smtp server address or domain name
'@: The username and password separated by commas (,). Whether or not it is determined by SMTP
MsgJmail. Send ("username: password@smtp.sina.com ")

'After sending, the sending log is displayed.
WScript. Echo (msgJmail. Log)

'Recycle objects
MsgJmail. Close ()
Set msgJmail = Nothing

After sending, a window will pop up showing the sending result.

Related Article

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.