Link to home
Start Free TrialLog in
Avatar of aswam1975
aswam1975

asked on

How to send email in perl script

How can I send email in a perl script.I am writing a perl script- after I create an output file, I would like to send out email to mailing list.
Avatar of mrhammi
mrhammi

Avatar of aswam1975

ASKER

is it possible to use "mail" command?
thanks for the tuotial, should Net::SMTP be installed? Does it come with the default?
I am not sure if the machines that this script will run have the Net::SMTP on it?Is there a simple mail command that I could use?
I'm not sure what you mean, I can't find any references to a mail command in perldoc.
What OS?  If on *nix, you could use sendmail.
http://www.perlfect.com/articles/sendmail.shtml
This is Linux RedHat- is it possible to use backtic and call the linux mail command or maybe use sendmail of some sort?
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks adam314- I will try that, unfortunately, I don't have Net::SMTP on the lib path- hence have to use something else
If you have sendmail, and are sending plain text, that is an easy way to go.  If you need to use SMTP or want to include attachments, it is much easier to use a module.
thanks- actually it is a solaris machine,so hte path is /usr/lib/sendmail
Is there a way to send to more than one person.Or is there a cc feature that I can use?
seperate them with a comma.  You can also use Cc: and Bcc:...

print MAIL "To: test\@testdom.com, test2\@testdom.com\n";
print MAIL "Cc: test3\@testdom.com, test4\@testdom.com\n";
print MAIL "Bcc: test5\@testdom.com, test6\@testdom.com\n";

thanks
is it possible to make the to address such that we can identify who the user is and send the email as:
user@hostname- without explicitly hardcoding it?
Instead of hard coding the from address: I did the following
print MAIL "From: mqmgr\@$server";
however,I dom't teceive any mail- $server = hostname
Did your $server include a "\n" at the end of it?
Did it work when it was hard coded?
ok-
when I hard coded it worked fine
Next, i got the server value from a config file, that worked fine
Next, I tried this
$server=`hostname`
print MAIL "From: mqmgr\@$server";
This does not work

does your `hostname` include the domain?
what is the output from:  print "server='$server'\n";
thank you for the info- i guess for now, I will try to use the config value as it seems to be working fine.
Is it possible to add a timestamp to the subject?
Instead of:
print MAIL "Subject: test subject\n\n";
do:
print MAIL "Subject: test subject$timestamp\n\n"
Yes, just create a $timestamp variable with whatever info you want it to have.