SMTP configuration SendUsing configuration value is invalid with ASP-Classic - asp-classic

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

Related

Microsoft VBScript runtime error Error Description: Object required: 'Server'

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.

My Classic ASP script contains both lines that require 32bit enabled and disabled application pools

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"
%>

Using classic ASP, is it possible to set the SMTP envelope from address with CDO?

I am sending mail using classic ASP with the CDOSYS objects, but I would like the envelope from address - that is, the one that is specified by MAIL FROM during SMTP - to be set differently to the From header address in the message.
The purpose of this is to implement VERP. For example, I would expect the SMTP dialogue to be something like:
220 mail.example.com ESMTP
[...]
MAIL FROM: <info+test=example.com#mydomain.test>
250 2.0.0 OK
RCPT TO: <test#example.com>
250 2.0.0 OK
DATA
354 Start mail input; end with <CRLF>.<CRLF>
From: Company1 <info#mydomain.test>
To: test#example.com
[...]
In the above example, the envelope from is "info+test=example.com#mydomain.test" but the From header is "info#mydomain.test".
Hope this makes sense. Any ideas?
ok I got it figured out and I wiresharked it and I see the commands as you want them...
Sorry about the horrible answer I gave you before. This will do it... it is the "SENDER" that you want for the MAIL FROM: envelope
Const cdoSendUsingPort = 2
StrSmartHost = "localhost"
set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")
With iConf.Fields
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
.Update
End With
With iMsg
Set .Configuration = iConf
.To = "test#example.com"
.Sender = "info+test=example.com#mydomain.test"
.From="Company1 <info#mydomain.test>"
.Subject = "This is a test CDOSYS message (Sent via Port 25)..."
.HTMLBody = strHTML
.Send
End With

Error in class referring - CDONTS

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.

Not receiving Delivery notifications in CDO

I have a function that uses CDO to send emails with request to have a delivery receipt when the mail reacehes the recepient.
I use the following code:
CDO.Message msg = new CDO.Message();
CDO.Configuration conf = new CDO.Configuration();
conf.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
conf.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = txtHost.Text;
conf.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = 25;
conf.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = txtPass.Text;
conf.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = txtUser.Text;
conf.Fields.Update();
msg.Configuration = conf;
msg.To = txtTo.Text;
msg.From = txtFrom.Text;
msg.Subject = txtSubject.Text+" " + DateTime.Now;
msg.HTMLBody = txtBody.Text;
msg.BodyPart.Charset = "utf-8";
msg.DSNOptions = CdoDSNOptions.cdoDSNSuccessFailOrDelay;
msg.Fields.Update();
msg.Send();
Now this works fine on my local machine with my web server, but when used in the production server with another mail server the delivery receipts were not received.
I believe there must be a difference between my mail server and the production mail server but I don't know what it can be exactly.
So please if anybody has faced such a problem before, tell me what to do.
It works on your local machine almost by accident because you're delivering it to yourself. To work out in the world you have to explicitly tell CDO not to deliver to the local smtp for relaying by specifying sendUsingPort
conf.Fields["ttp://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2

Resources