0

I have a classic asp project. On this project I need to send mail. I need helping hand to send mail from classical asp by using the bellow .config file information.

  <appSettings>
    <add key="smtpHost" value="smtp.gmail.com" />
    <add key="smtpPort" value="587" />
    <add key="emailTo" value="xxx@gmail.com" />
    <add key="emailFrom" value="yyy@gmail.com" />
    <add key="smtpUser" value="smtp.test@nazdaqTechnologies.com" />
    <add key="smtpUserPassword" value="test.smtp" />
    <add key="emailSubject" value="Email Auto Reorder for callback" />
    <add key="smtpDomain" value="" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>

In asp.net I use bellow syntax to send mail

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("luckyperson@online.microsoft.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);

I'm just getting into classical asp, so forgive me if this is a basic question. I need help to send mail by using the .config file information .

I Just want to be able to send an email from my website to a given email address using my gmail account (smtp server). I have the following code which others have using successfully, but i get error

<%
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

''# Authenticate if necessary
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username@googlemail.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mygmailpassword"

''# Outgoing SMTP server configuration
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

''# Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "username@googlemail.com" ''# This has to be valid email address on the selected SMTP server
strSubject = "Email test"
strHTML = "This is a test"
objCDOSYSMail.To = "username@hotmail.com"
objCDOSYSMail.Subject = strSubject
objCDOSYSMail.HTMLBody = strHTML
objCDOSYSMail.Send 
%>

enter image description here

This is a discussion on Error: 006~ASP 0177~Server.CreateObject Failed~800401f3 –asp show me the above error . Can any one help please to solve this issue------------------------------------------------------------------------------------------- Without Set objCDOSYSMail = Server.CreateObject("CDO.Message") The asp file was working fine on my os =win7 and win-server-2003 r2.

Keith
  • 20,636
  • 11
  • 84
  • 125
shamim
  • 6,640
  • 20
  • 85
  • 151
  • 1
    It is irritating to read a question that includes the text "I get an error" but the error itself is not included. You'd think it would be an obvious piece of information to include yet so many questioners miss out this vital info. What error do you actually get and if possible identify the line that throw the error??? – AnthonyWJones Feb 14 '12 at 18:03
  • Sorry AnthonyWJones to irritating you .I am new in classical asp,it's my first time on classical asp,Forget rest of the syntax after add the syntax=Set Mail = CreateObject("CDO.Message") ,page show error .My os=win7 and win-server-2003 r2 ,iis7 – shamim Feb 14 '12 at 19:20
  • 1
    Yes but what error is it showing? In IIS manager select you application and open the "Error Pages" feature, cliek "Edit Feature Settings...", from the dialog select "Detailed Errors". Now try to invoke your page, what error do you see in return page? – AnthonyWJones Feb 14 '12 at 20:29
  • shamim can you please post the error. – Pasha Immortals Feb 14 '12 at 21:44
  • Pasha lmmortals after configure the error on my iis get http-500 error message,Thanks AnthonyWJones help me to configure error page – shamim Feb 15 '12 at 04:17
  • Just a guess I see the URL is in localhost on port 8080. By any chance are you running this in Cassini (which is visual studio's internal web server)? or you are running it in IIS. Just wondering? Have a look at this link in regards to why I'm asking: http://stackoverflow.com/questions/3453762/debugging-classic-asp-in-visual-studio-2010 . Also look at this link if you are running it in IIS: http://support.microsoft.com/kb/261200 – Pasha Immortals Feb 15 '12 at 05:43
  • Set objCDOSYSMail = Server.CreateObject("CDO.Message") and Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") .show error “ 006~ASP 0177~Server.CreateObject Failed~800401f3 “ – shamim Feb 16 '12 at 05:59
  • See my reply in the comments section in my answer below. – Pasha Immortals Feb 16 '12 at 22:17

2 Answers2

1

Try this:

Set objEmail = Server.CreateObject("CDONTS.NewMail")
objEmail.to = "to_email@gmail.com"
objEmail.From = "your_email@domainname.com"
objEmail.Subject = "Subject"
objEmail.Body = "Email Body"
objEmail.send
Set objEmail = nothing

Also look here: http://support.jodohost.com/showthread.php?p=73224

UPDATE:

Look here for some asp code from MS. http://msdn.microsoft.com/en-us/library/ms972337.aspx

Pasha Immortals
  • 829
  • 1
  • 7
  • 19
  • Pasha Immortals thanks for reply,i fail to understand the first line,will you please like to explain for me,i want to understand the Server.CreateObject parameter,thanks again for reply – shamim Feb 14 '12 at 05:23
  • 2
    The code above is VBScript. When doing classic ASP the default language is VBScript, there is also JScript, not sure if there is others, but the above using the "Set objEmail = Server.CreateObject("CDONTS.NewMail")" is exactly like you were in c# doing "Object dummyObject= new Object();" in VBScript and older versions of VB, VBA CreateObject is used to create COM objects. In the above sample its "CDONTS.NewMail" (Collaboration Data Object for win NT). You might also want to look at CDOSYS depending on your systems. – Pasha Immortals Feb 14 '12 at 06:50
  • 2
    Also look at update I put in in my answer for classic ASP tutorial. It has it there as well (not CDONTS but ADODB.Connection which was the way to connect via ADO to DB's). From what I can remember thats the way we used to do it in classic ASP which is CDNTS and I think later we has to move to CDOSYS. So lookup them up and CDO in general as well. – Pasha Immortals Feb 14 '12 at 07:19
  • 1
    thanks Pasha Immortals,if my os=win7 if i use Set objCDOSYSMail = Server.CreateObject("CDO.Message") Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") syntax on my asp page show me error. – shamim Feb 14 '12 at 08:08
  • 2
    Please can you post your entire page and error produced on page + line number. Apologies in advance I'm not in a place right now to try things out but will tomorrow which is in 12-13hrs. Have a look at what this guy is doing on IIS 7, it could be closely configured to yours. http://forums.iis.net/t/1144383.aspx – Pasha Immortals Feb 14 '12 at 09:53
  • @shamim: First don't use CDONTS as outlined in this answer, its well out of date. – AnthonyWJones Feb 14 '12 at 18:01
  • Set objCDOSYSMail = Server.CreateObject("CDO.Message") and Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") .show error “ 006~ASP 0177~Server.CreateObject Failed~800401f3 “ – shamim Feb 16 '12 at 05:58
  • Mate if CreateObject fails its usually because it could not instantiate an object of that type, so if what you are saying in the above comment is true then it cannot instansiate "CDO.Message" and "CDO.Configuration". Here is a link to some one try to run it from a 64-bit environment and has the same issue and error as you. The main problem being is that you could be running from a 32-bit pool. Here is the link, see how you go: http://social.technet.microsoft.com/Forums/da/exchangesvrdevelopment/thread/335044b9-58bc-4782-b848-dc547609bfa9 – Pasha Immortals Feb 16 '12 at 22:16
1

How to send an email from one Gmail account to another one using a batch file or script?

Const schema   = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf

' E-mail properties
Set oMsg      = CreateObject("CDO.Message")
oMsg.From     = "from@gmail.com"  ' or "Sender Name <from@gmail.com>"
oMsg.To       = "to@gmail.com"    ' or "Recipient Name <to@gmail.com>"
oMsg.Subject  = "Subject"
oMsg.TextBody = "Text body"

' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver")       = "smtp.gmail.com"
oConf.Fields(schema & "smtpserverport")   = 465
oConf.Fields(schema & "sendusing")        = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic
oConf.Fields(schema & "smtpusessl")       = True
oConf.Fields(schema & "sendusername")     = "from@gmail.com"
oConf.Fields(schema & "sendpassword")     = "sender_password"
oConf.Fields.Update

oMsg.Send
Community
  • 1
  • 1
shamim
  • 6,640
  • 20
  • 85
  • 151