How to create mail using Mail::Outlook with Outlook 2007 - perl

I am trying to create a mail using Mail::Outlook. I followed this answers I believe is correct:
Sending email using Perl
Mail::Outlook CPAN
I created a simple code based from the tutorials:
use strict;
use warnings;
use Mail::Outlook;
use Data::Dumper;
my $outlook = new Mail::Outlook();
print Dumper($outlook);
print Dumper(Win32::OLE->LastError()); #added in response to comment
my $message = $outlook->create();
$message->To('sample#gmail.com');
$message->Cc('another#gmail.com');
$message->Subject('Testing sending mail from perl');
$message->Body('Hi, This is the body! wahahah!');
$message->save();
1;
The emails I used are real but I replaced it here for privacy's sake..
When I run the script, an error appeared:
$VAR1 = undef;
Can't call method "create" on an undefined value at send_mail.pl line 14.
It seems that the variable $outlook did not initialized during new Mail::Outlook(). The module Mail::Outlook returns undef if initiating a new object failed.. Now, I wonder why this happened.. I am thinking it was because of security issues of outlook but I don't know how to tweak that. Please perl masters out there, if anyone has the same experience or have encountered this, it would be helpful..
I am using Microsoft Outlook 2007 in windows 7 and I installed ppm install Mail-Outlook.
My main question is: How can I create a mail using Mail::Outlook in Outlook 2007
UPDATE
I tried using print Dumper(Win32::OLE->LastError()); and it printed this error:
$VAR1 = 'Win32::OLE(0.1709) error 0x80080005: "Server execution failed"';

After following what Tim Tom has instructed, with a little search, I saw an article about the error Win32::OLE(0.1709) error 0x80080005: "Server execution failed"
COM Process Elevation Mismatching
It says that the access level of the outlook application and perl script must be the same:
To make a long (and frustrating) story short, the problem was that I was running the script from a CMD.EXE window which was elevated (“Run as Administrator”). When I would run Outlook from a non elevated process (as a normal user would) there appeared to be a process elevation mismatch.
this is the same in my case.. I was running my cmd as Administrator while my outlook was running normally..
MSDN has a say to this:
COM security is aware of integrity levels and does not allow lower-integrity clients to bind to class instances running at a higher integrity level.
after changing my command line with the same elevation level as the outlook app, the perl script worked perfectly!
Note: perl crashes while using print Dumper(Win32::OLE->LastError()); if it has no errors..

Related

LWP::Simple getstore does not work in Windows

As a part of my Perl script I have the following simple command which is supposed to download a $url and store its contents to a file $file:
getstore("$url", "$file");
This works perfectly fine when I run it on my fedora Linux, however when I run the same code on Windows, it seems that the $file remains empty..
This is very strange since, as I mentioned, there was no change to the code and this command is very basic.
Maybe anyone has a clue why such behavior might occur?
Thanks!
Finding a proxy quite easy sometimes:
Try to open a nonexisting webpage and most of time the PROXY reports an error and print out its own details.
Try this: -.ds.com
Check the line: Your web proxy is:....

Handling Perl IIS 7.5

I've got a project written in classic asp, and a particular form's submit is handled by a Perl script.
I'm going to do an enhancement for this project. I installed the latest version of ActivePerl for Windows 32 bits.
I looked at the production environment and saw that in the IIS 7.5, there is an entry on "Handler Mappings" for *.pl to be handled by C:\Perl\bin\PerlEx30.dll. So I did the same thing on development environment. (please note that there is no mapping for "*.cgi" on the Prod. environment)
Now when I'm trying to submit the form which its action is MyScript.pl, I get the following error:
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
Maybe worth saying that, I'm on 64 bits environment, I tried ActivePerl for Windows 64 bits as well (I mapped *.pl to perl514.dll) but still getting the same error!
Your workaround was to use 32-bit version of perl. If you want to use the 64-bit version, this worked for me on IIS 8.5 Windows 2012 R2:
Add Module Mapping to your site:
Request path: *.pl
Module: CgiModule
Executable: C:\Perl64\bin\perl.exe "%s" %s
Name: Perl CGI
You can test it by creating the following 'hello world' page:
use strict;
use CGI;
my $page = new CGI;
my $msg = "Hello from ActivePerl CGI!";
print $page->header( "text/html" ),$page->start_html( $msg );
print $page->h2($msg);
print $page->end_html;
Name it something like test.pl, drop it into your webroot directory and browse to it to test.
The application pool was set so "Enable 32-Bit Applications = false", I change it to true, and it fixes the issue.
You haven't said whether or not you've gotten ANY Perl to work yet (even a "hello world"), or if the problem is this one particular script (perhaps just on this one particular server).
ANYWAY -
I doubt your Perl install is the problem.
You definitely need to do more troubleshooting.
I'd start with verifying whether a simple, one-line "hello world" will work.
Next, I'd "divide and conquer" to determine exactly WHERE the problem is. I'm guessing it's very probably somewhere in "MyScript.pl". I'm also guessing that it should be fairly easy to track down.
These links might help give you more clues as to exactly what you might look for as you "divide and conquer" (AFTER you've verified that Perl itself can be invoked from your IIS):
What causes an HTTP 405 "invalid method (HTTP verb)" error when POSTing a form to PHP on IIS?
http://www.tech-faq.com/troubleshooting-iis.html
PS:
I'm guessing the problem might be as simple as a missing, or inappropriate, URL in "MyScript.pl"!
PPS:
At the risk of repeating myself - please verify "helo_world.pl" first. If it doesn't work, please post the complete "hello_world" script and the complete error message(s).

Perl Location on Mac OSX

I'm beginning to write a simple Perl program on my Mac, and I understand that the first line needs to be the location of Perl itself, every example or tutorial I find tells me the first line should be:
"#!/usr/bin/perl"
However, with that there, I attempt to run the file under localhost and I get this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, you#example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Anyone have any idea why this is happening?
Thanks in advance, and let me know if any more information is needed!
P.S. if it helps, when I execute the command: "perl -v" it tells me
This is perl, v5.10.0 built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
As Erik said, /usr/bin/perl is the standard location for Perl on OSX. You can also verify this by running which -a perl from terminal (this will list all instances of Perl on your path).
Can you run your script from the command-line, i.e. ./<myscript>.pl? It's possible that you haven't made the script executable.
#!/usr/bin/perl is the correct path for 10.6. If you're running from the webserver, your first line before any output should be a HTML header. You may have forgotten one?
#!/usr/bin/perl
use CGI;
print CGI->header('text/html');
print "hello world";

What's the difference between sendmail via CGI vs. Perl?

I am using sendmail in perl and noticed (after much banging of head against wall) that when the script is run at the command line it needs you to leave out the \n(s) after your e-mail and the recipient's email address in order to format the mail correctly, but when running via CGI if those \n(s) aren't there it returns an error stating that the recipient's e-mail is malformed.
Has anyone else encountered this? What are the two doing differently?
I am betting that you are getting data from prompts in on the commandline and not chomping them like this:
my $send_to = <>;
This means $send_to will already have a "\n". To make them both work the same way chomp the variables:
my $send_to = <>;
chomp($send_to);
or just
chomp(my $send_to = <>);
In a couple of your comments you mention that you're running the script from the command line with the -l option (perl -l foo.cgi).
The -l option enables automatic line-ending processing, and as your problem is with line endings, I suggest you try it without the -l.
Where is the data coming from? Hard coded in the script, or from a web form?
Just as an aside, if you get the recipient's email address from a web form, your form will be used by spammers. It's a 100% guarantee.
The term "CGI" is broad, if you mean your perl script run as a CGI versus yur perlscript run at the command line, I would look toward the pathing that the script has and its general inherited environment. Especially if your running it as different userids. If the webserver is in a chroot, etc.
use Data::Dumper;
warn(Dumper(\%ENV));
So I'm guessing that you have something like this for running it via the command line:
my $your_email = "you#foo.bar";
my $recipient_email = "them#foo.bar";
and this when "running via CGI":
my $your_email = "you#foo.bar\n";
my $recipient_email = "them#foo.bar\n";
So the question I would ask you then is how you're calling sendmail with the above variables, and also what you mean when you say "running via CGI" versus running via the command line? Are you just adding CGI code and still running via the command line or by visiting its URL in a web browser?

Why can't Win32::OLE talk to Excel2003 under Win2003?

I have a Web-based Perl Win32::OLE script that uses Excel on the server side. It has been working happily for years on a Win2000 server running Excel2000. We recently upgraded to Win2003/Excel2003 and I now get the following error from the script:
Win32::OLE(0.1709) error 0x80070005: "Access is denied" at create_worksheet_lib.plx line 639
eval {...} called at create_worksheet_lib.plx line 639
line 639 is:
$Excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel";
It appears that Perl no longer has access to Excel. Any Windows gurus out there that might be able to help trouble shoot this?
Seems like the same wicked problem described in another post, however, no solution found...
Maybe troubleshooting with Procmon will reveal where the problem lies (see http://support.microsoft.com/kb/286198).
Can you run the script from a command line on the server (taking the web server out of the mix)? That's the first thing I'd try. If it works from the command line then it's probably a permissions issue or a web server configuration issue.