06 Sep 2010 
Support Center » Knowledgebase » How do I send out emails in ASP script? 我如何使用ASP程式發送電子郵件?
 How do I send out emails in ASP script? 我如何使用ASP程式發送電子郵件?
Solution

We provide JMail component on all windows platforms, you could use it to send out emails in ASP script, below are the sample codes:
我們在所有的Windows平台上提供 JMail 元件, 你可以在ASP script中使用它發送電子郵件, 以下是參考程式碼:


Sending HTML email from an ASP page
從一個ASP的頁面發送HTML電子郵件

<%@LANGUAGE="VBSCRIPT" CodePage=65001 %>
<HTML>
<BODY>
<%
Set jmail = Server.CreateObject("JMail.Message")
jmail.From = "user@yourdomain.com"
jmail.FromName = "User"
jmail.AddRecipient "user@recipientdomain.com", "Recipient Name"
' jmail.AddRecipientCC "user@recipientccdomain.com", "RecipientCC Name"
' jmail.AddRecipientBCC "user@recipientbccdomain.com", "RecipientBCC Name"
jmail.Subject = "Welcome to our service"
jmail.Charset = "utf-8"
jmail.Body = "Hello there, welcome to use our services."
jmail.HTMLBody = "<html><head><meta http-equiv='content-type' content='html/text; charset=utf-8'></head><body><h1>Hello there,<BR>Welcome to use our services.</h1></body></html>"
jmail.MailServerUserName = "smtp_username"
jmail.MailServerPassWord = "smtp_password"

if not jmail.Send("smtp.yourdomain.com") then
    Response.write "<pre>" & msg.log & "</pre>"
else
    Response.write "Message sent succesfully!"
end if
%>
</BODY>
</HTML>


Sending email with an attachment
發送帶有附件的電子郵件

<%@LANGUAGE="VBSCRIPT" CodePage=65001 %>
<HTML>
<BODY>
<%
Set jmail = Server.CreateObject("JMail.Message")
jmail.From = "user@yourdomain.com"
jmail.FromName = "User"
jmail.AddRecipient "user@recipientdomain.com", "Recipient Name"
' jmail.AddRecipientCC "user@recipientccdomain.com", "RecipientCC Name"
' jmail.AddRecipientBCC "user@recipientbccdomain.com", "RecipientBCC Name"
jmail.Subject = "Welcome to our service"
jmail.Charset = "utf-8"
jmail.Body = "Hello there, welcome to use our services."
jmail.HTMLBody = "<html><head><meta http-equiv='content-type' content='html/text; charset=utf-8'></head><body><h1>Hello there,<BR>Welcome to use our services.</h1></body></html>"
jmail.MailServerUserName = "smtp_username"
jmail.MailServerPassWord = "smtp_password"

' If you want to add a attachment, uncomment this and change the file path
jmail.AddAttachment("C:\attachment.zip")

if not jmail.Send("smtp.yourdomain.com") then
    Response.write "<pre>" & msg.log & "</pre>"
else
    Response.write "Message sent succesfully!"
end if
%>
</BODY>
</HTML>

Hints: 65001 is the character set of Unicode (UTF-8), you may refer to below URL for other character set
提示: 65001 是 Unicode (UTF-8) 的字符集, 你可以到以下網址參考其它的字符集.
http://support.nethub.com.hk/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=6



Article Details
Article ID: 1
Created On: 09 Nov 2007 03:28 AM

 This answer was helpful  This answer was not helpful

 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads
Language:

Help Desk Software By Kayako eSupport v3.60.04