Automating sendmail auto adding e-mail adress

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Guern1
    New Member
    • Mar 2007
    • 14

    Automating sendmail auto adding e-mail adress

    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

    Code:
    sub send_mail
    {
    	my $addr = shift;
    	my $msg = shift;'
    	my %mail;
    	my $body;
    
    	# start a new mail message
    
    	# setup the headers
    	%mail = (
    		To => 'fred@me.net',
    		From => 'bob@me.net',
    		subject =>' Warning information',
    		Message =>'This mail message was generated automatically 
    and has been sent to you because you have requested certain this information via email’,
    	);
    
    	# close the mail object (causes it to be sent)
    sendmail(%mail) or die $Mail::Sendmail::error;
    
    	print "OK. Log says:\n", $Mail::Sendmail::log;
    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
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Code:
    $msg  = "something";
    @list = (a list of email recipients);
    
    foreach $person (@list) {
       send_mail($person,$msg)
    }

    Comment

    • Guern1
      New Member
      • Mar 2007
      • 14

      #3
      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

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Code:
        sub send_mail
        {
        	my $addr = shift;
        	my $msg = shift;'
        	my %mail;
        	my $body;
        
        	# start a new mail message
        
        	# setup the headers
        	%mail = (
        		[B]To => $addr,[/B]
        		From => 'bob@me.net',
        		subject =>' Warning information',
        		[B]Message =>$msg,[/B]
        	);
        
        	# close the mail object (causes it to be sent)
        sendmail(%mail) or die $Mail::Sendmail::error;
        
        	print "OK. Log says:\n", $Mail::Sendmail::log;

        Comment

        • Guern1
          New Member
          • Mar 2007
          • 14

          #5
          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

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            Message =>"whatever you want here\n$msg";

            Comment

            • Guern1
              New Member
              • Mar 2007
              • 14

              #7
              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

              Comment

              Working...