Jmail email code

Source: Internet
Author: User
Some time ago, I sent a simple jmail email code. Today I will make a specific annotation for this code and add the code in two other formats. I will give you a few simple examples:
The core code of jmail. smtpmail is as follows:
<%
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
%>
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:
<%
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
%>
Let's talk about the mail sending method of the built-in cdonts component of Microsoft:
<%
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'
%>
This method is the easiest way to send emails, but it also brings about some problems, that is, few servers will launch this service!

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):
<%
'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 on which the email is sent
Jmail. addrecipient email 'email recipient
Jmail. sendername = sender 'email sender's name
Jmail. Sender = Fromer '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 = subject 'mail title
Jmail. Body = content 'mail content
'The password copy and CC are not used, and the two sentences are blocked here. If you need them, you can recover them here.
'Jmail. addrecipientbcc email 'address of the BCC recipient
'Jmail. addrecipientcc email 'address of the email CC recipient
Jmail. Execute () 'execute 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"

 

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.