How to use AspEmail

Source: Internet
Author: User
Tags chr mail mail code valid port number
Before using AspEmail you must create an object in your ASP script, for example:
<%
Set Mail = Server.CreateObject ("Persits.mailsender")
%>
Before you send a message, you first need to determine the address of an SMTP server and the corresponding port number (you can use the default value), such as:
Mail.host = "Smtp.mycompany.com"
Mail.port = 25 ' This option is optional. port 25 is the default value
The next step is to specify the e-mail address of the sender of the message, such as:
Mail.from = "Sales@mycompany.com"
Mail.fromname = "Sales Department" this option
You can then specify the recipient of the message, the CC recipient BCC receiver, and the reply address for the message, using the AddAddress, ADDCC, ADDBCC, and Addreplyto methods respectively. These methods receive two variables, mail addresses, and optional names.
Note: When using these methods, do not use the = symbol, and directly separate the variables with spaces and methods, such as:
Mail.addaddress "jsmith@company1.com", "Zhanghui"
MAIL.ADDCC the name "bjohnson@company2.com" is optional.

Use the subject and Body properties to specify the title of the message and the contents of the message, respectively. Body can use text or HTML, and you must set the IsHTML property to True if you want to use HTML. Take a look at the following examples:
Plain text mode
Mail.subject = "About Quote"
Mail.body = "Dear Mr. Zhang:" & Chr & Chr (a) & "Thank you for your letter, here are the quotations you need"
or HTML way
Mail.subject = "About Quote"
Mail.body = "mail.ishtml = True
If you need to send a file as an attachment to a message, you need to use the AddAttachment method. It supports ways to use a full physical path, such as:
Mail.addattachment "C:\dir\receipt.doc"
It is also necessary to note that the method does not need to use "=" to do the connection.
You can now send the content of the message, send the message using the Send method, and if you want to ignore possible errors, you can use the On Error Resume Next statement to skip and display the wrong information, such as:
On Error Resume Next
Mail.send
If Err <> 0 Then
Response.Write "Found an error, the error message is described as:" & Err.Description
End If
It is noteworthy that at present, many SMTP servers need to verify that the mail sender is a legitimate server user, that is, what we call the "Password Authentication function" At this time, we need to specifically specify the sender's username and password, the following methods:
Mail.username = "User name"
Mail.password = "Password"
Add the preceding two sentences to the Mail.send statement in use. Use the username and password you receive the message to replace the "username" and "password" above to send your message through a password-authenticated SMTP server; The following is an example of a practical operation that you can refer to using:

' Send mail
Strhost = "SMTP.SINA.COM.CN" ' specifies SMTP server
Set Mail = Server.CreateObject ("Persits.mailsender")
Mail.host = Strhost
Mail.from = "TEST@BESTDNS.NET"
mail.fromname = "Hai wei Company"
Mail.addaddress MAILADDRESS@CEDB.COM ' email address
MAIL.ADDCC "Service@cedb.com"

' Message subject
Mail.subject = "User Mail Notification" ' title of Message
Mail.username = Valid user name on "username" server
Mail.password = "password" ' Valid password on server
Mail.charset = "gb2312" ' E-mail code, use this option to avoid Chinese garbled
mail.ishtml = True ' Specifies the format of the message as HTML
Mail.body = "Mail.send



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.