in reply to Re: Mail::Sendmail multiline Message
in thread Mail::Sendmail multiline Message

Thanks again, Corion, you have been very helpful.

use Mail::Sendmail;
use vars qw(%mail) ;


%mail = ( To => 'ifasftp@chesterfield.gov',
From => 'burtonk@chesterfield.gov',
Subject => 'Test email from Perl',
Message => "< Many lines here"
);

sendmail(%mail) or die $Mail::Sendmail::error;

I am looking at the "Message" item where I would like to enter many lines like a normal email.
Ken

Replies are listed 'Best First'.
Re^3: Mail::Sendmail multiline Message
by Corion (Patriarch) on Mar 17, 2010 at 14:05 UTC

    So, what have you tried to put many lines into the parameter for Message? I ask, because the mechanisms that Perl supports are the same that the various shells, and certainly ksh support. Also see perlop on quotes and quote-like operators.

    Also, you could assign all the many lines to a variable and then use that variable as the value:

    my $message_text = "... many lines ..."; ... Message => $message_text, ...
      I will review the perlop and let you know how things go.
      Ken
        This is how I'm sending the contents of a file via mail:

        ($HC is the file path to the file I'm going to send)
        open(MAIL, "|mail $EMAIL"); print MAIL "To: $EMAIL\n"; print MAIL "From: $mail_from\n"; print MAIL "Subject: $mail_sub\n"; print MAIL "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; open(MESSAGE, "<", "$HC") or die "$!"; print MAIL <MESSAGE>; close(MESSAGE); close(MAIL);

        Update: I should note that the reason I don't use Corion's method listed above is because the file was already created before sending, and it seemed silly to me to read it all into a variable to send the variable. If the performance hit of reading/writing from a disk was already made, didn't seem much of a benefit to add more logic into the operation.
      I need to expand on my messages. My program needs to write out messages at different times, thus why I write out to a file. When program is finished, I need to mail the results with all the information from the message file. I believe the here document will not work.
      Ken

        You could instead of appending to a file, append to a variable that holds the message. But then again, who am I to question your beliefs.

      In ksh, I am creating lines like:
      echo "This is line1" >> mail_content (file)
      echo "this is line2" >> mail_content

      Then, "mail ..subject.. ip address.. < mail_content"

      I am assuming same process in Perl??
      Ken

        That's not the process I would have used under ksh. I would build up a variable in ksh using a here-document or a string that spans multiple lines. The equivalent process to your echo approach would be to append the strings to a variable using the dot operator (.). Maybe you want to read perlop now?