问题:
--------------------------------------------------------------------------------------------------------------------
IIS版本: Microsoft-IIS/5.0
支持发送邮件组件:
JMail.SmtpMail (Dimac JMail 邮件收发) √ 4.4
代码如下:
<%
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 = "smtp.163.com" '发送邮件的服务器
jmail.AddRecipient "xxx@163.com" '邮件的收件人
jmail.SenderName = "SenderName" '邮件发送者的姓名
jmail.Sender = "xxx@163.com" '邮件发送者的邮件地址
jmail.Priority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值
jmail.Subject = "Mail Subject" '邮件的标题
jmail.Body = "Mail Body" '邮件的内容
jmail.Execute() '执行邮件发送
jmail.Close '关闭邮件对象
response.write "ok"
%>
代码能够执行成功,但是不能接收到邮件?请问下是什么问题?
---------------------------------------------------------------------------------------------------------------------
主要是smtp服务器需要认证,如果是163的用户的话,你的程序中加上用户名和密码认证即可。
下面的代码引自Guest7(第七访客)
///
'========================================================
'函数名:SendMail
'作 用:用Jmail组件发送邮件(需要验证形式)
'说 明: Jmail4.3组件重新设计了其内部结构——使用
' Message对象代替原来的单一对象Jmail.smtpmail发送
' 邮件,有些方法需要身份验证的(如163、yahoo等),
' 可以用下面的方法解决:
'参 数:MailtoAddress ----收信人地址
' MailtoName -----收信人姓名
' Subject -----主题
' MailBody -----信件内容
' FromName -----发信人姓名
' MailFrom -----发信人地址
' MailServer -----用来发邮件的SMTP服务器地址
' Priority -----信件优先级
' MailServerUserName -----登录用户名
' MailServerPassWord -----登录密码
' MailDomain -----域名
'========================================================
function SendMail(MailtoAddress,MailtoName,Subject,MailBody,FromName,MailFrom,MailServer,Priority,MailServerUserName,MailServerPassWord,MailDomain)
on error resume next
Dim JMail
Set JMail=Server.CreateObject("JMail.Message")
if err then
SendMail= "<br/><li>没有安装JMail组件</li>"
err.clear
exit function
end if
JMail.Charset="gb2312" '邮件编码
JMail.silent=true
JMail.ContentType = "text/html" '邮件正文格式
JMail.ServerAddress= MailServer '用来发送邮件的SMTP服务器
'如果服务器需要SMTP身份验证则还需指定以下参数
JMail.MailServerUserName = MailServerUserName '登录用户名
JMail.MailServerPassWord = MailServerPassWord '登录密码
JMail.MailDomain = MailDomain '域名(如果用“name@domain.com”这样的用户名登录时,请指明domain.com
JMail.AddRecipient MailtoAddress,MailtoName '收信人
JMail.Subject=Subject '主题
JMail.HMTLBody=MailBody '邮件正文(HTML格式)
JMail.Body=MailBody '邮件正文(纯文本格式)
JMail.FromName=FromName '发信人姓名
JMail.From = MailFrom '发信人Email
JMail.Priority=Priority '邮件等级,1为加急,3为普通,5为低级
JMail.Send(MailServer)
SendMail =JMail.ErrorMessage
JMail.Close
Set JMail=nothing
End function
经测试利用以上代码可以发送到多数免费邮箱,但在发到我的Yahoo邮箱时出现了错误,服务器拒收邮件,不知是何故,以下是诺顿的邮件监控截图:
另外我根据JMAIL4.3的ASP Demo整理了一个函数,也可以发到163.com,qq.com,tom.com等多数邮箱,但也不能发送到Yahoo,此外还饶过了诺顿的邮件监控,并没有出现上图,以下是代码:
<%
'*************************************************
'* *
'* Produced by Dimac *
'* *
'* More examples can be found at *
'* http://tech.dimac.net *
'* *
'* Support is available at our helpdesk *
'* http://support.dimac.net *
'* *
'* Our main website is located at *
'* http://www.dimac.net *
'* *
'*************************************************
response.Write sendMail ("ljdzxx", "22503075@qq.com", "Subject", "Body", "Janylee", "22503075@163.com", "smtp.163.com", "xxx", "xxx")
Function sendMail(ToName, ToAddress, Subject, Body, FromName, FromAddress, MailServer, MailServerUserName, MailServerPassWord)
' Create the JMail message Object
Set msg = Server.CreateObject( "JMail.Message" )
' Set logging to true to ease any potential debugging
' And set silent to true as we wish to handle our errors ourself
msg.Logging = true
msg.silent = true
' Most mailservers require a valid email address
' for the sender
msg.FromName = FromName
msg.From = FromAddress
msg.MailServerUserName = MailServerUserName '邮件服务器登录用户名
msg.MailServerPassWord = MailServerPassWord '邮件服务器登录密码
' Next we have to add some recipients.
' The addRecipients method can be used multiple times.
' Also note how we skip the name the second time, it
' is as you see optional to provide a name.
'msg.AddRecipient "recipient@hisDomain.com", "His Name"
'msg.AddRecipient "recipientelle@herDomain.com"
msg.AddRecipient ToAddress, ToName
' The subject of the message
msg.Subject = Subject
' The body property is both read and write.
' If you want to append text to the body you can
' use JMail.Body = JMail.Body & "Hello world! "
' or you can use JMail.AppendText "Hello World! "
' which in many cases is easier to use.
'
' Note the use of vbCrLf to add linebreaks to our email
msg.Body = Body
' There.. we have now succesfully created our message.
' Now we can either send the message or save it as a draft in a Database.
' To save the message you would typicly use the Message objects Text property
' to do something like this:
'
' SaveMessageDraft( msg.Text )
' Note that this function call is only an example. The function does not
' exist by default, you have to create it yourself.
' If i would like to send my message, you use the Send() method, which
' takes one parameter that should be your mailservers address
'
' To capture any errors which might occur, we wrap the call in an IF statement
If Not msg.Send( MailServer ) Then
sendMail = msg.Log
Else
sendMail = "邮件发送成功!"
End If
' And we're done! the message has been sent.
End Function
%>