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
- // 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> ");
- }
- }
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.