Databases
cancel
Showing results for 
Search instead for 
Did you mean: 

using perl script to send emails

Jeff Paciolla_1
Frequent Advisor

using perl script to send emails

I am having trouble with the right syntax in my perl script to get an email sent at the time of execution. Below is an example of my script. Any help is appreciated.

Thanks
Jeff

open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq");
print(SENDMAIL) <<"EOF";
From: root@pikachu.acscltnt
To: jeff.paciolla@acs-inc.com
Subject: NNM Stats

Testing the email
EOF
close(SENDMAIL);

Here is the error I receive

syntax error in file ./ov-monthlystats.pl at line 80, next 2 tokens "root@pikachu"

3 REPLIES
Mark Greene_1
Honored Contributor

Re: using perl script to send emails

don't use sendmail directly, use mailx:

open(MF,"| mailx -s 'subject here' mailaddress@domainhere")

and then to send the mail, use print:

print MF ("variables and strings here")

HTH
mark
the future will be a lot like now, only later
Mark Greene_1
Honored Contributor

Re: using perl script to send emails

oops, I forgot, you still have to close it:

close(MF);

sorry about that
mark
the future will be a lot like now, only later
Craig Rants
Honored Contributor

Re: using perl script to send emails

This is what I generall will use.

open (SENDMAIL, "|/usr/sbin/sendmail johndoe\@yahoo.com < /tmp/filename") || die "$!";

Hope this helps,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut