如何使用经典的asp发送邮件 [英] how do I send mail using classic asp

查看:80
本文介绍了如何使用经典的asp发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我在使用经典asp编写的这个发送邮件代码中遇到了问题。这是一个古老的项目,仍然运作良好。任何人都可以帮我,注册邮件后必须发送到注册的电子邮件ID。但是下面的发送邮件代码不起作用。如果需要,请建议一些更改。



 Dim objMail,str1 

Dim smtpserver,youremail,yourpassword, ContactUs_Name,ContactUs_Tel,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError

smtpserver =smtp.live.com
youremail =test@hotmail.com
yourpassword =test123

'设置objMail = CreateObject(CDONTS.NewMail)
设置objMail = Server.CreateObject(CDO.Message)

objMail.From =在线入场支持< test2@hotmail.com >
objMail.To = session(Email)
'objMail.Cc =#
'objMail.Bcc =#
'objMail.Bcc =#

objMail.Subject =申请表注册详情
pwd =会话(passwordemail)
str1 =< div align = center > < table < span class =code-attribute> border = 0 width = 72% 高度 = 169 > < tr > < td > < p align = center > < img border = 0 src =' url' width = 155 height = 92 hspace = 8 vspace = 8 > < / td > < / tr > < tr > < td > < p align = left > < font face = Verdana size = 2 color = #000080 > 亲爱的< / font > < ; font face < span class =code-keyword> = Verdana size = 2 color = #0000FF > < / font > < font face = Verdana size = 2 颜色 = #000080 > & Session(Firstname)&& ;会话(姓氏)& < / font > < p align = left > < font face = Verdana style =' font-大小:9pt' 颜色 = #0033CC > 您已成功提交将您的申请表交给测试大学。< / font > < p align = left > < font face = Verdana style =' font-size:9pt' 颜色 = #0033CC > 您的Regi详细信息如下:< / font > < / td > < / tr > < tr > < td bgcolor = #F5F5F5 > < div < span class =code-attribute> align = center > < br > < table border = 0 width =' 68%' > < tr > < td align = 正确 width = 151 bgcolor = #FFFFFF > < font 颜色 = #000080 face = Verdana size = 2 > 申请编号:< / font > < / td > < td align = left bgcolor = #FFFFFF > < font face = Verdana style = ' font-size:9pt' 颜色 = #000080 > & session(app_no)& < / font > < span class =code-keyword>< / td > < / tr > < tr > < td align = 正确 width = 151 bgcolor = #FFFFFF > < font 颜色 = #000080 face = Verdana size = 2 > 用户名:< / font > < / td > < td align = left bgcolor = #FFFFFF > ; < font face = Verdana 样式 =' font-size:9pt' 颜色 =' #000080' > & Session(username)& < / font > < span class =code-keyword>< / td > < / tr > < tr > < td align = 正确 width = 151 bgcolor = #FFFFFF > < font 颜色 = #000080 face = Verdana size = 2 > 密码:< / font > < / td > < td align = left bgcolor = #FFFFFF > ; < font face = Verdana 样式 =' font-size:9pt' 颜色 = #000080 > & pwd& < / font > < span class =code-keyword>< / td > < / tr > < / table > < br > < / div > < / td > < / tr > < tr > < td > < p align = 对齐 > < < span class =code-leadattribute> font style =' font-size:9pt; font-weight:700' face = Verdana > 请仔细存储此电子邮件。< / font > < ; / p > < p align = 对齐 > < font face = Verdana size = 2 颜色 = #000080 > ; 目前您的应用程序状态为待定。< / font > < / p > < p align = left < span class =code-keyword>> < font face = Verdana size = 2 颜色 = #000080 > 我们收到您的申请表打印件,大学付款专栏副本和所有必要文件后,应用程序的状态将从< / font > < font face = Verdana size = 2 颜色 = #FF0000 > 待定< / font > < font face = Verdana size = 2 颜色 = #000080 > < / font > < font face = Verdana 大小 = 2 颜色 = #008000 > 已批准< / font > < font face = Verdana size = 2 颜色 = #000080 > < / font > < / p > < p align = left > < font face = Verdana < span class =code-attribute> size = 2 color = #000080 > 问候,< br > < / font > < font face = Verdana size = 2 颜色 = #800000 > < br > 支持团队入场。< / font > < br < span class =code-keyword>> < font < span class =code-attribute> face = Verdana size = 2 颜色 = #000080 < span class =code-keyword>> 测试大学< / font > < / p > < / td > < / tr > < / table > < / div >


objMail.Configuration.Fields.Item _
(http://schemas.microsoft.com/cdo/configuration/ sendusing)= 2
'远程SMTP服务器的名称或IP
objMail.Configuration.Fields.Item _
(http://schemas.microsoft.com/cdo/configuration/smtpserver )=smtp.live.com
'服务器端口
objMail.Configuration.Fields.Item _
(http://schemas.microsoft.com/cdo/configuration/smtpserverport )= 465
ObjSendMail.Configuration.Fields.Item(http://schemas.microsoft.com/cdo/configuration/smtpusessl)= true
objMail.Configuration.Fields.Update
ObjSendMail.Configurat ion.Fields.Item(http://schemas.microsoft.com/cdo/configuration/sendusername)=test@hotmail.com
ObjSendMail.Configuration.Fields.Item(http:// schemas .microsoft.com / cdo / configuration / sendpassword)=test123

'response.write str1

objMail.htmlBody = str1
objMail.Send
设置邮件=没有
response.write(邮件发送成功!)
结束如果

解决方案

< blockquote>将smptauthenticate属性添加为:



 objMail.Configuration.Fields.Item(   http://schemas.microsoft.com/cdo/configuration/smtpauthenticate)=  1  





另请注意,您在进行配置时使用ObjSendMail,但使用objMail发送电子邮件。所以用objMail替换ObjSendMail。



有些服务使用端口号587和25.如果它不能与您使用的465一起使用,请尝试使用这些端口号。


以下是您提供的代码中的多个问题。



1.您在进行配置时使用ObjSendMail但是使用发送电子邮件objMail。所以用objMail替换ObjSendMail。



2.在设置所有属性之前调用Fields.Update。



3.有一个声明SET Mail =什么都没有。但是对象的名称是objMail而不是Mail。



4.结尾处有一个结尾语句,但我找不到相应的if语句。 />




这是我使用gmail帐户测试的完整代码,它运行正常:



 <%@   LANGUAGE   =  VBSCRIPT %>  

<%
Dim objMail
设置 objMail = Server.CreateObject ( CDO.Message

smtpServer = smtp.live.com
yourEmail = youremail@hotmail.com
yourPassword = yourpassword

sendEmailTo = send_email_to@hotmail.com

objMail.From = yourEmail
objMail。 = sendEmailTo

objMail.Subject = 申请表注册详细信息

objMail.Configuration.Fields.Item(\"http://schemas .microsoft.com/cdo/configuration/sendusing\") = 2
objMail.Configuration.Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/smtpserver\") = smtpServer
objMail.Configuration. Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate\") = 1
objMail.Configuration.Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/smtpserverport\") = 465
objMail.Configuration.Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/smtpusessl\") = true
objMail.Configuration.Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/sendusername\") = yourEmail
objMail.Configuration.Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/sendpassword\") = yourPassword
objMail.Configuration.Fields.Item(\"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout\") = 6 0

objMail.Configuration.Fields.Update


objMail.htmlBody = \"This is test message\"
objMail.Send

Set objMail = Nothing
response.write(\"mail send successfully!\")
%>







You can try this code by replacing youremail@hotmail.com and yourpassword with actual email id and the password. If you are not using hotmail account then change the smpt.live.com also. For example, for a gmail account you have to use smtp.gmail.com


Refer



Send email using classic ASP[^]


Hello every one. I am having a problem in this send mail code written in classic asp. It is an old project and still working well. Can anyone pls help me, after registering the mail has to be sent to the registered email ID. But the send mail code below is not working. please suggest some changes if needed.

Dim objMail ,str1

Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Tel,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError

smtpserver = "smtp.live.com"
youremail = "test@hotmail.com"
yourpassword = "test123"

'Set objMail = CreateObject("CDONTS.NewMail")
Set objMail = Server.CreateObject("CDO.Message")

objMail.From = "Online Admission Support <test2@hotmail.com>"
objMail.To =session("Email")
'objMail.Cc="#"
'objMail.Bcc="#"
'objMail.Bcc="#"

objMail.Subject="Application Form Registration Details"
pwd=Session("passwordemail")
str1="<div align=center><table border=0 width=72% height=169><tr><td><p align=center><img border=0 src='url'width=155 height=92 hspace=8 vspace=8></td></tr><tr><td><p align=left><font face=Verdana size=2 color=#000080>Dear</font><font face=Verdana size=2 color=#0000FF></font><font face=Verdana size=2 color=#000080> "&Session("Firstname")&" "& Session("Surname") &"</font><p align=left><font face=Verdana style='font-size: 9pt' color=#0033CC>You have successfully submitted your Application Form to University of Test.</font><p align=left><font face=Verdana style='font-size: 9pt' color=#0033CC>Your Registration details are as follows:</font></td></tr><tr><td bgcolor=#F5F5F5><div align=center><br><table border=0 width='68%'><tr><td align=right width=151 bgcolor=#FFFFFF> <font color=#000080 face=Verdana size=2>Application Number : </font></td><td align=left bgcolor=#FFFFFF><font face=Verdana style='font-size: 9pt' color=#000080>" &session("app_no")& "</font></td></tr><tr><td align=right width=151 bgcolor=#FFFFFF><font color=#000080 face=Verdana size=2>Username :  </font></td><td align=left bgcolor=#FFFFFF><font face=Verdana style='font-size: 9pt' color='#000080'>" &Session("username")& "</font></td></tr><tr><td align=right width=151 bgcolor=#FFFFFF><font color=#000080 face=Verdana size=2>Password :  </font></td> <td align=left bgcolor=#FFFFFF><font face=Verdana style='font-size: 9pt' color=#000080>" & pwd & "</font></td></tr> </table><br></div></td></tr><tr><td><p align=justify><font style='font-size: 9pt; font-weight: 700' face=Verdana>Please store this email carefully.</font></p><p align=justify><font face=Verdana size=2 color=#000080>At present your Application's status is Pending.</font></p><p align=left><font face=Verdana size=2 color=#000080>As soon as we receive your Application form Printout, university copy of payment challan  and all necessary documents, your application's status will turn from </font><font face=Verdana size=2 color=#FF0000>Pending</font><font face=Verdana size=2 color=#000080> to </font><font face=Verdana size=2 color=#008000>Approved</font><font face=Verdana size=2 color=#000080>.</font></p><p align=left><font face=Verdana size=2 color=#000080>Regards,<br></font><font face=Verdana size=2 color=#800000><br>Support Team-Admissions.</font><br><font face=Verdana size=2 color=#000080>University of Test</font></p></td></tr></table></div>"


objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.live.com"
'Server port
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMail.Configuration.Fields.Update
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="test@hotmail.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") =" test123"

'response.write str1

objMail.htmlBody = str1
objMail.Send 
Set Mail = Nothing 
response.write("mail send successfully!")
end if

解决方案

Add the smptauthenticate property as:

objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1



Also note that you are using ObjSendMail while doing configuration but sending email using objMail. So replace ObjSendMail with objMail.

Some services use port number 587 and 25. So try these port numbers also if it does not work with 465 that you are using.


Here are multiple problems in the code provided by you.

1. You are using ObjSendMail while doing configuration but sending email using objMail. So replace ObjSendMail with objMail.

2. Fields.Update is called before setting all the properties.

3. There is a statement SET Mail = nothing. But the name of object is objMail and not Mail.

4. There is an end if statement at the end, but I could not find corresponding if statement.


Here is a complete code that I tested using a gmail account and it works fine:

<%@LANGUAGE="VBSCRIPT"%>

<%
Dim objMail 
Set objMail = Server.CreateObject("CDO.Message")
 
smtpServer = "smtp.live.com"
yourEmail = "youremail@hotmail.com"
yourPassword = "yourpassword"

sendEmailTo = "send_email_to@hotmail.com"

objMail.From = yourEmail
objMail.To = sendEmailTo
 
objMail.Subject="Application Form Registration Details"

objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = yourEmail
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourPassword
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMail.Configuration.Fields.Update
 
 
objMail.htmlBody = "This is test message"
objMail.Send 

Set objMail = Nothing 
response.write("mail send successfully!")
%>




You can try this code by replacing youremail@hotmail.com and yourpassword with actual email id and the password. If you are not using hotmail account then change the smpt.live.com also. For example, for a gmail account you have to use smtp.gmail.com


Refer

Send email using classic ASP[^]


这篇关于如何使用经典的asp发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆