发送html邮件
以 WINDOWS 而言,本身有內建寄送元件,但是依照版本的不同,而有所差別。假設你的 MAIL 沒有要求複雜的功能,倒是可以直接使用內建元件。
CDONTS(WIN 2000)
CDONTS
<%@ LANGUAGE=VBScript%>
<%
Response.Buffer = True
Response.Expires = 0
'创建对象实例
Set myMail = Server.CreateObject("CDONTS.NewMail")
'以下是将要发送的内容
HTML = "<html>"
HTML = HTML & "<head>"
HTML = HTML & "<title>Sending CDONTS Email Using HTML</title>"
HTML = HTML & "</head>"
HTML = HTML & "<body bgcolor=""FFFFFF"">"
HTML = HTML & "<p><font size=7>"
HTML = HTML & "This is a test mail in html<br>"
HTML = HTML & "Mail content here ...</font></p>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"
'发件人
myMail.From = "somebody@somewhere.com"
'收件人
myMail.To = "nobody@somewhere.com"
'密件抄送
myMail.Bcc = "nobody@somewhere.com"
'抄送
myMail.Cc = "nobody@somewhere.com"
'邮件的重要性
' 0 重要性低
' 1 重要性一般(默认)
' 2 重要性高
myMail.Importance = 2
'邮件主题
myMail.Subject = "Test mail in HTML"
'附件(注意 e:\test.txt 指的是服务器上的位置,如果使用相对路径,必须用 Server.MapPath 映射为真实路径)
myMail.AttachFile "e:\test.txt"
'NewMail 对象的文字格式
'0 表示该 Body 可包含超文本置标语言 (HTML)
'1 表示该 Body 只用于纯文本(默认值)
myMail.BodyFormat = 0
'NewMail 对象设置编码
'0 表示将采用 MIME 格式
'1 表示将采用连续的纯文本(默认值)
myMail.MailFormat = 0
'给邮件对象的文本赋值
myMail.Body = HTML
'将邮件发出
myMail.Send
'销毁对象实例,释放内存
Set myMail = Nothing
%>
寫成函數
Function SendNewMail( Recipients,Blind_copy_recipients,Copy_recipients,Importance,Subject,Attachments,BodyFormat,MailFormat,Message)
Dim myMail
Set myMail = Server.CreateObject("CDONTS.NewMail")
On Error Resume Next
'以下是將要發送的內容
'發件人
myMail.From = "mabeldeng@LOCAL.WONDERLAND.COM.TW" 'Sender mabeldeng MISADM
'收件人
myMail.To = Recipients
'密件抄送
myMail.Bcc = Blind_copy_recipients
'抄送
myMail.Cc = Copy_recipients
'郵件的重要性
' 0 重要性低
' 1 重要性一般(默認)
' 2 重要性高
myMail.Importance = Importance
'郵件主題
myMail.Subject = Subject
'附件 (注意 C:\Inetpub\wwwroot\warning.gif 指的是服務器上的位置, 如果使用相對路徑, 必須用 Server.MapPath 映射為真實路徑)
if Attachments <> "" then
myMail.AttachFile Attachments
end if
'NewMail 對象的文字格式
'0 表示該 Body 可包含超文本置標語言(HTML)
'1 表示該 Body 只用於純文本(默認值)
myMail.BodyFormat = BodyFormat
'NewMail 對象設置編碼
'0 表示將採用 MIME 格式
'1 表示將採用連續的純文本(默認值)
myMail.MailFormat = MailFormat
'給郵件對象的文本賦值
myMail.Body = Message
'將郵件發出
myMail.Send
'銷毀對象實例,釋放內存
Set myMail = Nothing
If Err.Number <> 0 Then
SendNewMail=false
Exit Function
end if
SendNewMail=true
End Function
故障排除:
1 CDONTS.NewMail不能发邮件
1 确定已经安装了IIS的SMTP服务。
2 在IIS管理器中,设置smtp服务的属性。在中继对话框里设置“仅除以下列表以外”。因为默认情况下它只给某列表中列出的服务器转信,但是这个列表是空的,所以发不出去。
2 无法登陆SQL SERVER
这是因为安装SQL SERVER时使用了NT验证模式,而ASP以匿名身份运行,不够资格访问数据库服务器。解决方法:把SQL SERVER改成混合验证模式(包含SQL验证)
3 ODBC访问Access时出现无法访问注册表关键字的错误
错误信息为:
Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'
[Microsoft][ODBC Microsoft Access Driver]常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN for process 0x4ec Thread 0x81c DBC 0x22f3544 Jet'。
这是因为Windows2000 SP2以后的新bug造成的。也许微软不喜欢ODBC了,所以出此下策。正确的方法是使用OLEDB来连接Access。连接字符串为:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库文件名
4 权限问题
ASP没有权限访问某些文件夹。因此运行VB编写的组件可能会出毛病。设置system32文件夹的属性,赋予IUSR用户运行权限即可。ASP也没有权限访问注册表。这个可以用组件来实现。把组件注册到COM+里,然后指定其以高级身份运行;或者取消虚拟目录的“匿名访问”,让访客输入管理员密码,这时候ASP就提升为管理员身份运行了。ADSI也是一样。
如果Access数据库存放在受保护的文件夹,就会出现80004005错误。此时也需要设置文件夹的权限。
5 加密问题
MD5不是加密算法,因此不能解密。要传输加密数据,关键是不能把算法暴露在客户端。所以根本别想把客户端的数据加密传到服务器上。
6 保护知识产权
ASP基本上算是不能加密的东西。不要用screnc编码工具。那根本是个垃圾。要加密,就只能用组件技术了。去学VB吧!
7 安全问题
别想偷偷摸摸的从客户端上传文件。<input type=file>绝对不可能用脚本预先设置文件名。脚本语言没有权限访问客户端的硬盘,客户端组件和控件即使签名也会提示是否安装……这一切,都是为了访客的安全。要不然你把访客的硬盘format了怎么办?
8 与其他商家的合作问题
想发短信,可以联系移动运营商;想开商场,可以找银行做支付接口。这两项服务都要求在服务器上注册组件,所以挑选虚拟主机时要多加选择,避免花冤枉钱。
CDO(WIN XP, WIN 2003)
CDO.Message
如何用cdo发送一个url.
Dim iMsg
iMsg=Server.CreateObject("CDO.Message")
Dim iConf
iConf=Server.CreateObject("CDO.Configuration")
Dim Flds
Set Flds = iConf.Fields
Flds(cdoURLProxyServer) = "myserver:80"
Flds(cdoURLProxyBypass) = "<local>"
Flds(cdoURLGetLatestVersion) = True
Flds.Update
With iMsg
Set .Configuration = iConf
.CreateMHTMLBody "http://InternalNTLMAuthRequiredServer", _
"domain\username", _
"password"
.To = "MyCustomer@microsoft.com"
.From = "me@microsoft.com"
.Subject = "an example mhtml formatted message with attachment"
.AddAttachment "http://www.microsoft.com"
.Send
End With
JMail
當你灌好jmail4.4,隨著安裝精靈安裝完成,就已完成安裝.
不用再regsvr32 jmail.dll 囉!
而安裝好,你要到你的安裝目錄下.C:\program files\
找到jmail的folder夾,在裡面會有他附的說明文件,好像是PDF的檔案,如果沒記錯的話,
裡面有ssmple.外加各總參數的解說及用法..
你要么有一个独立的外部IP地址的服务器,因为自己的电脑做为服务器 是不支持发邮件的,
Jmail的意思是譬如对于免费邮箱,就是你的用户名和密码,当然还有个server一般外面是mail.****类似的,譬如etang,free.smtp.etang.com 然后就是你的登陆名和密码
<%
Set jmail = Server.CreateObject("JMAIL.SMTPMail") '建立一個JMAIL對像
jmail.silent = true 'JMAIL不會拋出例外錯誤,返回的值為FALSE跟TRUE
jmail.logging = true '啟用使用日誌
jmail.Charset = "GB2312" '郵件文字的程式碼為簡體中文
jmail.ContentType = "text/html" '郵件的格式為HTML的
jmail.ServerAddress = "Server Address" '發送郵件的伺服器
jmail.AddRecipient Email '郵件的收件人
jmail.SenderName = "SenderName" '郵件發送者的姓名
jmail.Sender = "Email Address" '郵件發送者的郵件地址
jmail.Priority = 1 '郵件的緊急程式,1 為最快,5 為最慢, 3 為預設值
jmail.Subject = "Mail Subject" '郵件的標題
jmail.Body = "Mail Body" '郵件的內容
jmail.AddRecipientBCC Email '密件收件人的地址
jmail.AddRecipientCC Email '郵件抄送者的地址
jmail.Execute() '執行郵件發送
jmail.Close '關閉郵件對像
%>
w3 Jmail4.3組件重新設計了其內部結構——使用Message對像代替原來的單一對像Jmail.smtpmail發送郵件,有些方法需要身份驗證的(如163、yahoo等),可以用下面的方法解決:
<%
Set jmail = Server.CreateObject("JMAIL.Message") '建立發送郵件的對象
jmail.silent = true '屏蔽例外錯誤,返回FALSE跟TRUE兩值j
mail.logging = true '啟用郵件日誌
jmail.Charset = "GB2312" '郵件的文字編碼為國標
jmail.ContentType = "text/html" '郵件的格式為HTML格式
jmail.AddRecipient Email '郵件收件人的地址
jmail.From = "Email From for Sender" '發件人的E-MAIL地址
jmail.MailServerUserName = "UserName of Email" '登入郵件伺服器所需的使用者名
jmail.MailServerPassword = "Password of Email" '登入郵件伺服器所需的密碼
jmail.Subject = "Mail Subject" '郵件的標題
jmail.Body = "Mail Body" '郵件的內容
jmail.Prority = 1 '郵件的緊急程式,1 為最快,5 為最慢, 3 為預設值
jmail.Send("Server Address") '執行郵件發送(通過郵件伺服器地址)
jmail.Close() '關閉對像
%>
寫成子程式
<%
Sub SendAction(subject, mailaddress, email, sender, content, fromer)
Set jmail = Server.CreateObject("JMAIL.SMTPMail") '建立一個JMAIL對像
jmail.silent = true 'JMAIL不會拋出例外錯誤,返回的值為FALSE跟TRUE
jmail.logging = true '啟用使用日誌
jmail.Charset = "GB2312" '郵件文字的程式碼為簡體中文
jmail.ContentType = "text/html" '郵件的格式為HTML的
jmail.ServerAddress = mailaddress '發送郵件的伺服器
jmail.AddRecipient Email '郵件的收件人
jmail.SenderName = sender '郵件發送者的姓名
jmail.Sender = fromer '郵件發送者的郵件地址
jmail.Priority = 1 '郵件的緊急程式,1 為最快,5 為最慢, 3 為預設值
jmail.Subject = subject '郵件的標題
jmail.Body = content '郵件的內容
'由於沒有用到密抄跟抄送,這裡屏蔽掉這兩句,如果您有需要的話,可以在這裡恢復
'jmail.AddRecipientBCC Email '密件收件人的地址
'jmail.AddRecipientCC Email '郵件抄送者的地址
jmail.Execute() '執行郵件發送
jmail.Close '關閉郵件對像
End Sub
'調用此Sub的範例
Dim strSubject,strEmail,strMailAdress,strSender,strContent,strFromer
strSubject = "這是一封用JMAIL發送的測試郵件"
strContent = "JMail組件發送測試成功!"
strEmail = "runbing@eyou.com"
strFromer = "runbing@eyou.com"
strMailAddress = "mail.ubbcn.com"
Call SendAction (strSubject,strMailaddress,strEmail,strSender,strContent,strFromer)
%>
<%
Sub SendEMailProc(EMail)
set msg = Server.CreateOBject( "JMail.Message" )
'生物件
msg.Logging = true
'開記錄功能
msg.Subject = "你的主旨"
msg.From = "mymail address"
msg.FromName = "my name"
msg.AddRecipient Trim(EMail)
msg.Charset = "BIG5" '設定電郵的編碼
HTML = "test<BR>"
'msg.Body = HTML '設定內文
'如果您的內文為HTML就用下列
msg.HTMLBody = HTML
if not msg.Send( "stmp server domain" ) then
Filename1="maillog/"&Replace("maillog-"&date&".log","/","_")
Set fs2 = Server.CreateObject("Scripting.FileSystemObject")
File1 = Server.MapPath(Filename1)
Set txtf2 = fs2.OpenTextFile(File1,8,true)
txtf2.write EMail & msg.log & CHR(13)& CHR(10) '寫紀錄入檔案
Set txtf2 = Nothing
Set fs2 = Nothing
else
Filename1="maillog/"&Replace("maillog-"&date&".log","/","_")
response.write Filename1
Set fs2 = Server.CreateObject("Scripting.FileSystemObject")
File1 = Server.MapPath(Filename1)
Set txtf2 = fs2.OpenTextFile(File1,8,true)
txtf2.write EMail & "..ok" & CHR(13)& CHR(10)'寫紀錄入檔案
Set txtf2 = Nothing
Set fs2 = Nothing
end if
End Sub
%>