ASP sends mail with JMail, CDO

Source: Internet
Author: User


Some time ago there was a simple JMail e-mail sent the code, today, the code to make a specific note, and add two other formats of code, with a few simple examples:
The first is the core code of Jmail.smtpmail:

<%&NBSP;
Set jmail = Server.CreateObject (" JMail. SmtpMail ") ' Creates a JMail object  
Jmail.silent = True ' JMail does not throw exception errors, the returned value is false and true 
Jmail.logging = True ' Enable the use of log  
JMail. Charset = "GB2312" message text code for Simplified Chinese  
JMail. ContentType = "text/html" message is formatted as HTML  
JMail. serveraddress = "Server Address"   for sending mail;
JMail. AddRecipient email ' recipient  
JMail. SenderName = the name of the sender of the "sendername" message  
JMail. Sender = "Email address" e-mail sender's email  
JMail. Priority = 1 ' message urgent program, 1 is the fastest, 5 is slowest, 3 is the default value  
JMail. Subject = "Mail Subject" message title  
JMail. BODY = "Mail Body" message content  
JMail. ADDRECIPIENTBCC Email ' bcc address  
JMail. ADDRECIPIENTCC Email ' email cc's address  
JMail. Execute () ' Execute mail send  
JMail. Close ' Closes the mail object  
%>

W3 Jmail4.3 component redesign of its internal structure-- Use the Message object instead of the original single object jmail.smtpmail send mail, some methods require authentication (such as 163, Yahoo, etc.), can be resolved by the following method:  
<% 
Set jmail = Server.CreateObject ("JMail. Message ") ' establishes the object that sent the message  
Jmail.silent = True ' Mask exception error, return False with true two value j 
Mail.logging = True ' Enable mail logging  
JMail. Charset = "GB2312" The text encoding of the message is GB  
JMail. ContentType = "text/html" message is in HTML format  
JMail. AddRecipient Email ' e-mail recipient's address  
JMail. from = "e-mail from Sender", "Sender's email address  
JMail. Mailserverusername = "UserName of email" ' Username   required to log on to the mail server;
JMail. Mailserverpassword = "Password of email" ' Password   required to log in to the mail server;
JMail. Subject = "Mail Subject" message title  
JMail. BODY = "Mail Body" message content  
JMail. prority = 1 ' message urgent program, 1 is the fastest, 5 is slowest, 3 is the default value  
JMail. Send ("server address") ' performs mail delivery (via mail server addresses)  
JMail. Close () ' closes object  
%>

Let's talk about the method of sending the CDONTS component from Microsoft:

<%
Set Cdomail = Server.CreateObject ("CDONTS. NewMail ") to create a mail object
Cdomail. Subject = "Mail Subject" message header
Cdomail. From = "Sender's Mail" ' Sender's address
Cdomail. to = Address of the "Email would from" recipient
Cdomail. Body = contents of "Mail Body" message
Cdomail. Send ' execute sending
%>

This method of sending mail is the simplest, but also brings a certain problem, is that few servers will open this service!


We write programs, in general, the code is to be modular, so as to facilitate maintenance, but also easy to transplant. Therefore, I am here to write this e-mail as a subroutine, in the call can be called directly (of course, if you are happy to write a function is also possible, this is mainly to see personal interests):

<%
' Parameter description
' Subject: Message header
' MailAddress: The address of the sender server, such as smtp.163.com
' Email: Recipient email Address
' Sender: The sender's name
' Content: Message contents
' 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 error, the returned value is false and true
Jmail.logging = True ' Enable use of log
JMail. Charset = "GB2312" message text code for Simplified Chinese
JMail. ContentType = "text/html" message is in HTML format
JMail. serveraddress = MailAddress ' send mail to server
JMail. AddRecipient Email ' email recipients
JMail. SenderName = Sender ' e-mail sender's name
JMail. Sender = Fromer ' e-mail address of sender
JMail. Priority = 1 '

%>

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.