ASP sends emails using jmail and CDO

Source: Internet
Author: User

I sent a simple jmail email some time ago. Code Today, we will make a specific annotation for this code, and add the code in the other two formats, and give a few simple examples:
The core code of jmail. smtpmail is as follows:
Program Code

<%
Set jmail = server. Createobject ("jmail. smtpmail") 'creates a jmail object
Jmail. Silent = true 'jmail does not throw exception errors. The returned values are false and true.
Jmail. Logging = true' enable use Log
Jmail. charset = "gb2312" 'the email text code is simplified Chinese
Jmail. contenttype = "text/html" 'the email format is html
Jmail. serveraddress = "server address" 'server for sending emails
Jmail. addrecipient email 'email recipient
Jmail. sendername = "sendername" 'name of the email sender
Jmail. Sender = "email address" 'email address of the sender
Jmail. Priority = 1' urgent mail program, 1 is the fastest, 5 is the slowest, 3 is the default
Jmail. Subject = "mail subject" 'mail title
Jmail. Body = "mail body" 'mail content
Jmail. addrecipientbcc email 'address of the BCC recipient
Jmail. addrecipientcc email 'email CC address
Jmail. Execute () 'execute the mail to send
Jmail. Close 'Close the email object
%>

There are still many programs that use this method to send mail. This method has a major defect, that is, the mail is sent using the local SMTP service on the server and has not passed any SMTP authentication,
If the server is set to require authentication, the mail fails. Due to the need for anti-spam, more and more servers are paying attention to this setting problem. If you use this method to send emails suddenly become abnormal,
The server may restrict anonymous sending, and the above Code will not work properly.

We do not recommend this method, but there are still many ASP programs using this method, which may still work normally, but it is difficult to ensure that it will continue to work normally in the future, in addition, some email servers reject the emails sent by this method. If possible, try not to use this method.

W3 jmail4.3 component re-designs its internal structure -- uses the message object instead of the original single object jmail. smtpmail sends an email. Some methods require authentication (such as 163 and Yahoo). You can use the following methods to solve this problem:
Program code

<%
Set jmail = server. Createobject ("jmail. Message") 'creates the email sending object.
Jmail. Silent = true' to block exception errors. The values false and true are returned. j
Mail. Logging = true' enable Mail Log
Jmail. charset = "gb2312" 'the text of the email is encoded as the national standard
Jmail. contenttype = "text/html" 'the mail format is html
Jmail. addrecipient email 'email recipient's address
Jmail. From = "email from for Sender" 'sender's E-MAIL address
Jmail. mailserverusername = "username of email" 'username required to log on to the email server
Jmail. mailserverpassword = "password of email" 'Password required to log on to the email server
Jmail. Subject = "mail subject" 'mail title
Jmail. Body = "mail body" 'mail content
Jmail. prority = 1' urgent mail program, 1 is the fastest, 5 is the slowest, 3 is the default
Jmail. Send ("server address") 'executes the mail sending (via the mail server address)
Jmail. Close () 'Close the object
%>

Using this code to send emails is currently the most stable and applicable method. We recommend that you use jmail to send emails.

Let's talk about the mail sending method of the built-in cdonts component of Microsoft:
Program code

<%
Set cdomail = server. Createobject ("cdonts. newmail") 'to create a mail object
Cdomail. Subject = "mail subject" 'mail title
Cdomail. From = "sender's mail" 'sender's address
Cdomail. To = "email will from" 'recipient's address
Cdomail. Body = "mail body" 'mail content
Cdomail. Send'
%>

We write programs. Generally, code modularization is required, which facilitates maintenance and migration. Therefore, I will write this email as a child program here, which can be called directly during the call (of course, if you are happy to write it as a function, this is mainly for personal interest):
RecommendationCopy codeThe Code is as follows: <%
'Parameter description
'Subject: Mail title
'Mailaddress: the address of the sender server, such as smtp.163.com
'Email: Recipient's email address
'Sender: sender name
'Content: email content
'Fromer: the sender's email address

sub sendaction (subject, mailaddress, email, sender, content, Fromer)
set jmail = server. createobject ("jmail. smtpmail ") 'creates a jmail object
jmail. silent = true 'jmail does not throw exception errors. The returned values are false and true
jmail. logging = true' enable use Log
jmail. charset = "gb2312" 'the email text code is simplified Chinese
jmail. contenttype = "text/html" 'the email format is HTML
jmail. serveraddress = mailaddress 'server for sending emails
jmail. addrecipient email 'email recipient
jmail. sendername = sender' name of the sender
jmail. sender = Fromer 'email sender's email address
jmail. priority = 1' email Emergency Program, 1 is the fastest, 5 is the slowest, 3 is the default value
jmail. subject = subject 'mail title
jmail. body = content 'email content
'because the password copy and CC are not used, these two sentences are blocked here. If you need them,
'jmail. addrecipientbcc email 'address of the BCC recipient
'jmail. addrecipientcc email 'email CC address
jmail. execute () 'Run the mail to send
jmail. close 'close the email object
end sub

'Example of calling this sub
Dim strsubject, stremail, strmailadress, strsender, strcontent, strfromer
Strsubject = "this is a test email sent using jmail"
Strcontent = "jmail component sending test successful! "
Stremail = "runbing@eyou.com"
Strfromer = "runbing@eyou.com"
Strmailaddress = "mail.ubbcn.com"

Call sendaction (strsubject, strmailaddress, stremail, strsender, strcontent, strfromer)

%>

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.