By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,221 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,221 IT Pros & Developers. It's quick & easy.

Automating sendmail auto adding e-mail adress

P: 14
Help Please

I am very new to the Perl game and need some help

I have a Perl application which works fine and can output some plain text information that I need to send to selected users via e-mail.

The e-mail address are under the $addr and the information that I whish to put in the e-mail message are held in $msg

I have installed and have working Sendmail the script that I have come up with so far is

Expand|Select|Wrap|Line Numbers
  1. sub send_mail
  2. {
  3.     my $addr = shift;
  4.     my $msg = shift;'
  5.     my %mail;
  6.     my $body;
  7.  
  8.     # start a new mail message
  9.  
  10.     # setup the headers
  11.     %mail = (
  12.         To => 'fred@me.net',
  13.         From => 'bob@me.net',
  14.         subject =>' Warning information',
  15.         Message =>'This mail message was generated automatically 
  16. and has been sent to you because you have requested certain this information via emailí,
  17.     );
  18.  
  19.     # close the mail object (causes it to be sent)
  20. sendmail(%mail) or die $Mail::Sendmail::error;
  21.  
  22.     print "OK. Log says:\n", $Mail::Sendmail::log;
  23.  
This sends an e-mail as shown above fine

How do I get the $addr tag to automatically put the recipients email address into the to field?

Secondly how do I get the $msg tag to automatically put its information into the e-mail message.

This will I guess be either very easy or am I asking the impossible?
I have now spent severally days searching the net and trying to work this out so any help would be most appreciated
May 9 '07 #1
Share this Question
Share on Google+
6 Replies


KevinADC
Expert 2.5K+
P: 4,059
Expand|Select|Wrap|Line Numbers
  1. $msg  = "something";
  2. @list = (a list of email recipients);
  3.  
  4. foreach $person (@list) {
  5.    send_mail($person,$msg)
  6. }
May 9 '07 #2

P: 14
Hi KevinADC

Thanks for the reply

Being new at Perl I donít think I fully explained myself.

The $addr has the e-maill address that I want to use what I cant see is how to put the value/ email address that $addr has in to the e-mail to field.

Thanks
May 9 '07 #3

KevinADC
Expert 2.5K+
P: 4,059
Expand|Select|Wrap|Line Numbers
  1. sub send_mail
  2. {
  3.     my $addr = shift;
  4.     my $msg = shift;'
  5.     my %mail;
  6.     my $body;
  7.  
  8.     # start a new mail message
  9.  
  10.     # setup the headers
  11.     %mail = (
  12.         To => $addr,
  13.         From => 'bob@me.net',
  14.         subject =>' Warning information',
  15.         Message =>$msg,
  16.     );
  17.  
  18.     # close the mail object (causes it to be sent)
  19. sendmail(%mail) or die $Mail::Sendmail::error;
  20.  
  21.     print "OK. Log says:\n", $Mail::Sendmail::log;
May 9 '07 #4

P: 14
Hi

Thanks for all the help
I am almost there now all the right information is now sent in the email
The only problem now is the formatting of the body of the email
as you can see below all the lines of text are in the wrong order

Subject: Warning information

:
Information 10-May-2007 2320z country: hungary-Ha zone: 15 baa->dx: 1603km rule: 6
: conditions or rare stations be reported by email.
Date: Thu, 10 May 2007 23:20:59 +0000
Content-Transfer-Encoding: 8bit
To: me@cs.net
and has been sent to you because you have requested certain propagation
: This mail message was generated automatically by software
Mime-Version: 1.0


The message should read

This mail message was generated automatically by software
and has been sent to you because you have requested certain propagation
conditions or rare stations be reported by email.

Information 10-May-2007 2320z country: hungary-Ha zone: 15 dxg->dx: 1603km rule: 6

I am so close now to getting this working I have spent the last day reading and trying sendmail settings with limited success.

Also

Date: Thu, 10 May 2007 23:20:59 +0000
Content-Transfer-Encoding: 8bit
To: me@cw.net
Also get put in the email

Thanks for any help

Keith
May 10 '07 #5

KevinADC
Expert 2.5K+
P: 4,059
Message =>"whatever you want here\n$msg";
May 11 '07 #6

P: 14
Many thanks for all your help

All is now working as I want it to

I have learnt a lot along the way

Many thanks again

Keith
May 12 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.