ASP Outgoing Mail control

Source: Internet
Author: User
Tags throw exception

<%
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 = "Server Address" for sending mail servers
JMail. AddRecipient Email ' email recipients
JMail. SenderName = The name of the "sendername" Mail Sender
JMail. Sender = e-mail address of the sender of "e-mail Address"
JMail. Priority = 1 ' Urgent program for mail, 1 is fastest, 5 is slowest, 3 is default
JMail. Subject = title of "Mail Subject" message
JMail. Body = contents of "Mail Body" message
JMail. ADDRECIPIENTBCC Email ' BCC address
JMail. ADDRECIPIENTCC Email ' email CC's address
JMail. Execute () ' Send mail
JMail. Close ' Closing mail objects
%>
The W3 Jmail4.3 component redesigned its internal structure--using the Message object instead of the original single object jmail.smtpmail send mail, some methods need authentication (such as 163, Yahoo, etc.), can be solved by the following method:
<%
Set JMail = Server.CreateObject ("JMail. Message ") to set up 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" message text encoding for GB
JMail. ContentType = "text/html" message is in HTML format
JMail. AddRecipient Email ' email Recipient's address
JMail. From = e-mail address of the sender from the ' for sender '
JMail. Mailserverusername = "UserName of email" ' username required to log in to the mail server
JMail. Mailserverpassword = "Password of email" ' Password required to log on to the mail server
JMail. Subject = title of "Mail Subject" message
JMail. Body = contents of "Mail Body" message
JMail. Prority = 1 ' Urgent program for mail, 1 is the fastest, 5 is slowest, and 3 is the default value
JMail. Send ("server address") ' Execute mail send (via mail server addresses)
JMail. Close () ' Closed 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 ' Urgent program for mail, 1 is fastest, 5 is slowest, 3 is default
JMail. Subject = Subject ' title of message
JMail. Body = Content ' contents of the message '
"Because there is no use of the secret copy and Cc, here to block out the two sentences, if you need, you can restore here
' JMail. ADDRECIPIENTBCC Email ' BCC address
' JMail. ADDRECIPIENTCC Email ' email CC's address
JMail. Execute () ' Send mail
JMail. Close ' Closing mail objects
End Sub

' Example of calling this sub
Dim Strsubject,stremail,strmailadress,strsender,strcontent,strfromer
Strsubject = "This is a test message sent with JMail"
Strcontent = "JMail component sent test successfully!" "
Stremail = "[Email protected]"
Strfromer = "[Email protected]"
strmailaddress = "Mail.ubbcn.com"

Strsender= "I sent the Mail"

SendAction (strsubject,strmailaddress, Stremail, Strsender, Strcontent, Strfromer)

ASP Outgoing Mail control

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.