Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

HTML
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
Posted
Updated 1-Apr-14 20:40pm
v2

Add the smptauthenticate property as:

VB
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.
 
Share this answer
 
v2
Comments
rgboss 3-Apr-14 1:45am    
Hello Charan, thanks for reply. I have done the changes but still it is not working.
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:

VB
<%@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
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900