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.
Related
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.
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 set up SendGrid account and got key and pw.
My VisualBasic 2015 console app runs DeliverAsync without error, but email doesn't get to Internet receipients (my Hotmail account).
Also, the task.wait() throws exception "Bad username / password", which is posted at the end
Wireshark on Azure shows no SMTP, but I don't know if SendGrid uses SMTP.
Here is the app:
' Create the email object first, then add the properties.
Dim myMessage As SendGridMessage
myMessage = New SendGridMessage()
' Add the message properties.
myMessage.From = New MailAddress("<my email addr>")
' Add multiple addresses to the To field.
myMessage.AddTo("<destination email addr 1>")
myMessage.AddTo("<destination email addr 2>")
myMessage.AddTo("<destination email addr 3>")
myMessage.Subject = "Testing the SendGrid Library 2"
'Add the HTML and Text bodies
myMessage.Html = "<p>Hello World!</p>"
myMessage.Text = "Hello World plain text!"
Dim credentials As NetworkCredential
credentials = New NetworkCredential("apikey", "<my api pw>")
transportWeb = New Web(credentials)
Dim task = transportWeb.DeliverAsync(myMessage)
Try
task.wait()
Catch ex As AggregateException
Stop '<<<<<<<<< I GET: "Bad username / password"
Catch
End Try
EXCEPTION DETAILS:
"Bad username / password"
DeliverAsync returns a Task, so you need to await the task.
Await transportWeb.DeliverAsync(myMessage)
Of course, to use the await keyword your method needs to be marked as async. If you don't want to do that, then you can manually wait on the task.
Dim task = transportWeb.DeliverAsync(myMessage)
task.Wait()
You should familiarize yourself with the Task-based Asynchronous Pattern (TAP). Often when a function name ends in -Async then it uses TAP.
I got it working by creating new VB web app instead of win app.
VB > create new proj > web app > MVC and then props > references > NU.. Mgr > search SendGrid > Install, and that's it.
I've developed a Web Application (web site) using VS 2010 and VB.NET. I'm able to run the application successfully from VS. But when I Publish and upload it on my hosting server this error message occurs.
Retrieving the COM class factory for component with CLSID {7F017F97-9257-11D5-87EA-00B0D0BE6479} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I've downloaded the SOAP toolkit 3.0 and imported it in my application reference. here is my code:
Imports MSSOAPLib30
Dim objSoapClient As New SoapClient30 '=== Create an instance of SoapClient
'=== Set Client Properties
objSoapClient.ClientProperty("ServerHTTPRequest") = True
'=== Retrieve KWMP web services WSDL
Call objSoapClient.mssoapinit("https://example.com/ReferencePayment?WSDL", "ReferencePayment")
'=== Set connection property to be over SSL
objSoapClient.ConnectorProperty("UseSSL") = False
'=== Now consume the web sevices according to KWMP Specification
Dim output As String = objSoapClient.verifyTransaction(RCode, "00105952-129251")
--Update--
except the method above, I was thinking of using POST web method to consume the SOAP XML.
here is the xml request generated by WCF Test Client:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
</s:Header>
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<q1:verifyTransaction xmlns:q1="urn:Foo">
<String_1 xsi:type="xsd:string">12345678901234567890</String_1>
<String_2 xsi:type="xsd:string">00109902-129251</String_2>
</q1:verifyTransaction>
</s:Body>
</s:Envelope>
and I have method to consume the SOAP XML which returns Internal Server Error 500 !!!!! You think which part is wrong ?!
Public Function ServiceCall(RefCode As String) As String
Dim resultXml As String
Dim wbrqst As WebRequest = WebRequest.Create("https://modern.enbank.net/ref-payment/ws/ReferencePayment?WSDL")
Dim httpreq As HttpWebRequest = DirectCast(wbrqst, HttpWebRequest)
httpreq.Method = "POST"
httpreq.ContentType = "Content-Type: text/xml; charset=utf-8"
httpreq.Headers.Add("SOAPAction", "https://modern.enbank.net/ref-payment/ws/ReferencePayment")
'httpreq.Headers.Add("<Action s:" + "ReferencePayment>")
httpreq.ProtocolVersion = HttpVersion.Version11
httpreq.Credentials = CredentialCache.DefaultCredentials
Dim requestStream As Stream = httpreq.GetRequestStream()
Dim streamWriter As New StreamWriter(requestStream, Encoding.ASCII)
Dim sb As New StringBuilder()
sb.Append("<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>")
sb.Append("<s:Body s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>")
sb.Append("<q1:verifyTransaction xmlns:q1='urn:Foo'>")
sb.Append("xml:xsd='http://www.w3.org/2001/XMLSchema'")
sb.Append("<verifyTransaction xmlns='urn:Foo'")
sb.Append("<String_1 xsi:type='xsd:string'>12345678901234567890</String_1>")
sb.Append("<String_2 xsi:type='xsd:String'>00109902-129251</String_2>")
sb.Append("</q1:verifyTransaction> </s:Body></s:Envelope>")
streamWriter.Write(sb.ToString())
streamWriter.Close()
Dim wr As HttpWebResponse = DirectCast(httpreq.GetResponse(), HttpWebResponse)
Dim srd As New StreamReader(wr.GetResponseStream())
resultXml = srd.ReadToEnd()
Return resultXml
End Function
There appears to be a problem with that tool, you may want to use the WCFTest Client, which should work with you soap message, thise can be found from within the VS2010 folder
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe
Just add the service you want to open, it should then create a client proxy for you on the fly.
Update:
You may want to use add web reference and create a webservice project as part of a VS project.
Hope this helps.
Cheers
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