Am trying to run daily sql job which sends mail to my client using SMTP Server and CDONT Mail objects . Already has the code which works fine for me. Recently i have upgraded the my server from microsoft Server 2003 to 2012 and Sql server 2005 to 2014.
This code below works fine in Classic asp in server. But in sql job getting error
Set objEMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi#xx.in"
objEMail.From ="hello#yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
Executed as user: NT Service\SQLSERVERAGENT. Error Code: 0 Error Source= Microsoft VBScript runtime error Error Description: Object required: 'Server' #
Server is an object that is specific to ASP Classic.
Your code is probably run by the Windows Script Host (wscript.exe / cscript.exe), which has its own CreateObject function.
Simply remove the Server. to make it work.
Set objEMail = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set Confi = objConfig.Fields
Confi("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Confi("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
Confi.Update
Set objEMail.Configuration = objConfig
objEMail.To = "hi#xx.in"
objEMail.From ="hello#yy.com"
objEMail.Subject = "Email subject goes here"
objEMail.HTMLBody = "Hi Sql job data"
objEMail.Send
Set objEMail = Nothing
For the record, the Server is optional in ASP Classic as well, the above code would work in both environments.
Related
I recently migrated my ASP.Net website from a traditional windows 2003 shared server to Azure as a Web App. My VBScript forms which send e-mails to me have stopped working since the migration. I have tried a few different approaches to get my VBScript email code to work but have had no luck so far. Part of the problem is that I can't see what the error is.
The first part of my question is: How do I make the ASP.Net errors on my VBScript ASP page visible? I have set debug='true' in my web.config and I tried to set it on my ASP page (see below) but this hasn't worked. Currently I just get an 'Internal error 500' page after attempting to send the email with no indication of what went wrong.
Here is the code that sends the e-mail and appears to be the source of the problem. Can do I change this to work under Azure without rewriting my entire page in C#?
<%# Language=VBScript Debug='true' %> 'Debug=true doesn't work
Set Mailer = Server.CreateObject("Persits.MailSender")
Mailer.Host = "mail.mydomain.com" ' Specify a valid SMTP server
Mailer.From = Request.Form("AgentEmail") ' Specify sender's address
Mailer.FromName = Request.Form("AgentsName") ' Specify sender's name
Mailer.Port = 587
Mailer.isHTML = True
Mailer.AddAddress "person1#email.com"
Mailer.AddAddress "person2#email.net"
Mailer.AddAddress "person3#email.com"
Mailer.AddAddress Request.Form("AgentEmail")
Mailer.Body = "stuff in my email"
Mailer.Username = "me#emailcom"
Mailer.Password = "123456"
On Error Resume Next
Mailer.Send
If Err <> 0 Then
Response.Write "Error encountered: " & Err.Description
Else
Response.Write "Success"
End If
This code did work on my old Windows server. I've left out all of the HTML since that part appears to work just fine.
Assuming you're using Azure Websites (and not an Azure VM), you can use Classic ASP provided you jump through some hoops: https://khailiangtech.wordpress.com/2011/06/03/windows-azure-how-to-enable-classic-asp-support/
Windows Azure seems to support CDO (the built-in COM SMTP service) whereas your code is using Persits.MailSender - it might be possible to install the Persits.MailSender component via the <ServiceDefinition> XML - but I don't recommend this because of the 32/64-bit problem.
I suggest changing your script to use CDO instead, here's a reference: http://theholmesoffice.com/using-sendgrid-with-classic-asp-to-send-emails/ (the page is for using SendGrid's SMTP server, but you can use any SMTP server (just don't use port 25).
You're trying to instantiate an object from a DLL that is not installed: Server.CreateObject("Persits.MailSender")
You can't install any external COM object when using Web Apps. One option is to use a Virtual Machine and install your COM DLL.
For future reference, I ended up solving my problem by converting my code to C# and using to smtpClient. This is the general idea here:
SmtpClient smtpClient = new SmtpClient("mail.domain.com", 587);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(From, "password");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Port = 587;
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(From, "Me");
smtpClient.Host = "mail.domain.com";
message.From = fromAddress;
message.To.Add(To);
message.Subject = Subject;
message.IsBodyHtml = true;
message.Body = Body;
smtpClient.Send(message);
Label_Results.Text = "Email successfully sent.";
}
catch (Exception ex)
{
ErrorLabel.Text = "<p>Send Email Failed:<p>" + ex.Message;
}
I collect mail addresses from database and send mails using old Classic ASP. JMail requires 32Bit mode disabled in application pool.
Set sender = Server.CreateOBject("JMail.Message")
Recently I've added Oracle DB to collect more mail addresses and noticed the code below requires an application pool with 32Bit mode enabled:
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.35.200)(PORT=1521)))(CONNECT_DATA=(SID=MYDB)(SERVER=DEDICATED)));User Id=MYNAME;Password=MyPass;"
It looks like a weird dilemma. What would be the workaround/solution in my case?
I would change to an ASP Email component that does not have the conflicting requirement. Personally, I've used ASPEmail. It's a google away :).
I've learned very well & used CDO years later. Here is my code:
<%
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
dim objEmail
Set objEmail = CreateObject("CDO.Message")
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")= cdoSendUsingPort
'Name or IP of remote SMTP server
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.domain.com"
'Server port
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpAuthenticate") = cdoBasic
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "info#domain.com"
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "thepassword"
objEmail.BodyPart.Charset = "Windows-1254"
'objEmail.TextBodyPart.Charset = "utf-8"
'objEmail.HTMLBodyPart.Charset = "utf-8"
'objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/SaveSentItems") = TRUE
objEmail.Configuration.Fields.Update
objEmail.From = "My Name <myname#domain.com>"
objEmail.To = "The Name <name#targetmail.com>"
objEmail.Subject = "CDO Test"
objEmail.Textbody = "This is a message."
objEmail.HTMLBody = "<h1>This is a message.</h1>"
objEmail.Send
Response.Write "OK"
%>
I'm trying to connect to SQL Server 2008 from a Classic ASP page:
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "
Provider= SQLOLEDB.1
DataBase= MYDBNAME
Server= SERVERNAME\INSTANCE
Integrated Security = True
Trusted_Connection=Yes
Persist Security Info = False"
conn.Open -> error 80040e21 Multiple-step OLEDB operation generated errors
sql = "select * from UsersQuery where ID=" & ID
Set rs = conn.Execute(sql)
In SQL Server Log I can see that the connection was successful:
Login succeeded for user 'dbuser' Connection made using Windows
Authentication.
What is causing the error?
Thank You.
Does it works ?
Provider=SQLNCLI11;Server=ServerName\Instance;Database=MYDBNAME;Integrated Security=SSPI;DataTypeCompatibility=80;MARS Connection=True;
I get an error at the following line in my application:
'create NewMail object'
Line 96: Function SendHTMLEMail (strFrom, strTo, strCC, strSubject, strBodyHTML)
Line 97: Set objNewMail = Server.CreateObject("CDONTS.NewMail")
The error is:
Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid class string
/Utils.inc, line 97
I have added interop.CDONTS.dll to the references of application, but still I am getting same error.
I am not sure if this functionality is used in any other page and is working.
I use .NET 2003 framework 1.1, and the server is running Windows Server 2003
ASP-Classic
Since CDONTS is discontinued since Win2000 and newer you should switch to CDOSYS.
Sample code for sending via remote server
Set oMessage = CreateObject("CDO.Message")
Set oConfig = CreateObject("CDO.Configuration")
Set oFields = oConfig.Fields
With oFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.acme.com"
.Update
End With
With oMessage
Set .Configuration = oConfig
.To = "recipient#acme.com"
.From = "sender#acme.com"
.Subject = "A Subject Line"
.TextBody = "A Text body message"
.Fields.Update
.Send
End With
The linked site features detailed examples for all kinds of scenarios.
ASP.NET
If you are targeting ASP.NET you should use System.Net.Mail instead of CDO
I got the solution. I added a new CDONTS.dll and registered it using
regsvr32 C:\SYSROOT\system32\cdonts.dll
This solved the problem. No need of adding it to the references.
I'm trying to get an email sent using ASP classic, and am having trouble with SMTP configuration.
The error:
CDO.Message.1 error '80040220' The "SendUsing" configuration value is
invalid.
The Code(for the email itself):
Set objMsg = Server.CreateObject("CDO.Message")
objMsg.From = "name#name.com"
objMsg.To = "themetatron#gmail.com"
objMsg.Subject = "Procurement Ally Update"
objMsg.TextBody = strBody
The Code I tried to configure with (pt 1):
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "smtpserver") = "127.0.0.1"
.update
End With
That didn't work, so I tried:
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMsg.Configuration.Fields.Update
That also didn't work.
(Yes, I didn't show it, but at the end there's a call to objMsg.Send)
As far as I can tell, the local boxes SMTP service is running and ready to do its duty.
Can anyone help?
If you are specifying an smptserver, be sure to set your 'sendusing' field to 2 (or cdoSendUsingPort) as well:
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMsg.Configuration.Fields.Update
As the SMTP service is on the localhost it makes more sense to send to pickup directory using SendUsingPickup (1). This will be more efficient than sending over network to port 25.
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
objMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\Inetpub\mailroot\Pickup"
objMsg.Configuration.Fields.Update