[Kc] perl and cdosys?

C.J. Scheppers cscheppers at kc.rr.com
Sat Mar 10 00:42:19 PST 2007


Hello fellow Perl Mongers!

I am trying to write a perl call to a web host's CDOSYS email 
interface.  The web host provides a visual basic script to do this 
but since everything I have written for the site is in perl, I'd like 
to write the email call in perl, too.  This will be an auto-responder 
when someone completes a form.  I succeeded (with help from an 
on-line article which I cannot find again)  in adapting perl for a 
call to CDONTS on another web host for a different client.  But this 
time, it's CDOSYS on the present client's web host.  I can send one 
email with the code at the bottom of the page, but only one, and then 
I have to wait many hours before another one can be sent.  It doesn't 
seem to be reliable.  Sending two emails in succession (one to buyer 
and one to seller) results in no emails sent at all.

Anybody have a comment on this?  Point me in a direction?  I searched 
the web for info, found hundreds of examples of VB and CDOSYS but 
none for perl and CDOSYS.  It's even hard to find useful info on 
CDOSYS.  Perl reads so well and other languages are so bizarre!

Thanks,

C.J.

###############
#set up the info required for email

$smtpserver = "127.0.0.1";
$youremail = "sales at automobileconvertibletops.com";
$yourpassword = "";  #No need to add a password on Gate.com's servers

#Grabbing variables from the form post
$ContactUs_Name = "cjs";
$ContactUs_Email = $in{'address'};
$ContactUs_Subject = $in{'subject'};
$ContactUs_Body = $in{'body'};
$Action = "SendMail";
$times = $in{'times'};

############
#this is a working perl script calling cdonts on another web host:

#use Win32::OLE;
#my $NewMail = Win32::OLE-> new('CDONTS.NewMail');
#$NewMail-> {From} = 'info at timesavertools.com';
#$NewMail-> {To} = 'natpublisher at fake.com';
#$NewMail-> {Cc} = "";
#$NewMail-> {Subject} = "Incoming Order";
#$NewMail-> {BodyFormat} = 0;
#$NewMail-> {MailFormat} = 0;
#$NewMail-> {Body} = "Check your <a 
href=\"http://www.timesavertools.com/cgi-bin/list.pl\"><img 
src=\"http://www.timesavertools.com/_images/database.gif\" 
width=\"150\" height=\"20\" border=\"0\"></a> for a recently placed 
order from $in{'company'}.
#";
#$NewMail-> Send();
#print Win32::OLE-> LastError();
#print "\n";
#$NewMail = undef;
#undef($NewMail);

################
#example of  perl script I used to write the perl script above:
#   use Net::SMTP;
#   my $MailObj = Net::SMTP-> new ("CDO.Message");
#    $MailObj-> {From} = "sender at mydomain.com";
#    $MailObj-> {To} = "recipient at theirdomain.com";
#    $MailObj-> {Subject} = "Test message";
#    $Text = "Thank you for your submission.
#    Your request is being processed.
#    Please allow 48 hours for a response.";
#    $MailObj-> {TextBody} = $Text;
#    $MailObj-> Send;
#    $MailObj =  undef;
#    undef($MailObj);

###########
#example of VB calling cdosys:

#<%
#Dim MyMail
#Set MyMail = Server.CreateObject("CDO.Message")
#MyMail.From = "justme at myaddress.com"
#MyMail.To = "friend1 at address1.com;friend2 at address2.com"
#MyMail.Cc = "friend3 at address3.com;friend4 at address4.com"
#MyMail.Bcc = "friend5 at address5.com;friend6 at address6.com"
#MyMail.Subject = "Sending Mail via CDOSYS for Windows 2000/XP"
#MyMail.TextBody = "Sending email with CDOSYS Message " &_
#      "objects is easy! Try it!"
#MyMail.AddAttachment "c:\path\smiley.gif"
#MyMail.Fields("urn:schemas:httpmail:importance").Value = 2;
#MyMail.Fields.Update()
#MyMail.Send()
#Set MyMail = Nothing	#nothing is a vb keyword meaning an 
uninitialized object value,
#  or to disassociate an object variable from an object to release 
system resources
#%>

################
#this is VB calling cdosys script provided by current web host:

#	Dim ObjSendMail
#	Set ObjSendMail = CreateObject("CDO.Message")
#	my $ObjSendMail = Win32::OLE-> new ('CDO.message');

	#This section provides the configuration information for the 
remote SMTP server.

#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/sendusing") = "2"; 
#Send the message using the network (SMTP over the network).
#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = 
"$smtpserver";
#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 
"25";
#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 
#Use SSL for the connection (True or False)
#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") 
= "60";

#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 
"1"; #basic (clear-text) authentication
#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/sendusername") = 
$youremail
#	ObjSendMail.Configuration.Fields.Item 
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = 
$yourpassword

#	ObjSendMail.Configuration.Fields.Update

	#End remote SMTP server configuration section==

#	ObjSendMail.To = $youremail;
#	ObjSendMail.Subject = $ContactUs_Subject;
#	ObjSendMail.From = $ContactUs_Email;

	#we are sending a html email.. simply switch the comments 
around to send a text email instead
	#ObjSendMail.HTMLBody = strBody
#	ObjSendMail.TextBody = $ContactUs_Body;

#	ObjSendMail.Send;

#	Set ObjSendMail = "Nothing";


###########
for ($x=0;$x<$times;$x++) {	#send one or more emails

#the perl script I am currently trying. I tried to translate the VB 
above into perl:

use Win32::OLE;

$act_sendmail = Win32::OLE-> new("CDO.Message");	#trying 
$act_sendmail 5:44pm instead of $sendmail

#print $act_sendmail produces Win32::OLE=HASH(0x1a34cac)

$iConf = Win32::OLE-> new("CDO.Configuration");

#Set Flds = iConf.Fields

#sendusing") = "2";
$iConf->{SendUsingMethod} = "2";

#smtpserver") = "$smtpserver";
#$iConf->{cdoSMTPServer} = "mail-fwd";
$iConf->{SMTPServer} = "$smtpserver";

#smtpserverport") = "25";
$iConf->{SMTPServerPort} = "25";

#smtpusessl") = False
$iConf->{smtpusessl} = "False";

#smtpconnectiontimeout") = "60";
$iConf->{SMTPconnectiontimeout} = "60";

#smtpauthenticate") = "1";
$iConf->{smtpauthenticate} = "1";

#sendusername") = $youremail
$iConf->{smtpauthenticate} = $youremail;

#sendpassword") = $yourpassword
$iConf->{smtpauthenticate} = $yourpassword;

#$iConf->Update;	#13 () doesn't work, try update call without ()

#Set ObjSendMail.Configuration = iConf
$act_sendmail->{Configuration} = $iConf;

$act_sendmail->{From} = 'sales at automobileconvertibletops.com';
$act_sendmail->{To} = $ContactUs_Email;
$act_sendmail->{Subject} = $ContactUs_Subject;
$act_sendmail->{BodyFormat} = 0;
$act_sendmail->{MailFormat} = 0;
$act_sendmail->{TextBody} = $ContactUs_Body;
$act_sendmail->{Importance} = 1;

#$sendmail->Send();	#3,13,16  () doesn't work, try send call without ()
$act_sendmail->Send;	#4,17

#$sendmail = "Nothing";	#5
#$act_sendmail = undef;	#20, 22
undef($act_sendmail);	#3,4, 19, 22

#$error = $sendmail->{sendError};	#$error in html below seems 
to make script not run

#$iConf = undef;	#20, 22
undef($iConf);	#3,4, 19, 22

}

#print an acknowledgement page:

print "Content-type: text/html\n\n";

print<<HTML;
<HTML>
<HEAD>
<TITLE>ACT Management</TITLE>
</head>
<body>
<center>
Script ran, what else happened?
<br>answer = $sendmail->{sendError}
<br>sent = $sent
<br>wildcard = $!
</center>
</body>
</html>

HTML

exit;


More information about the kc mailing list