How to send email from perl-script with different priorities : normal

Hello,

I'm trying to send email from my perl-script with different
priorities : normal or high.
For some reasons, I'm not going to use any perl-module like
MIME::Lite.

$email = "my.email\ [at] isp.com";
$priority = 'high';

$html = "MIME-Version: 1.0\nContent-Type: text/html\; charset=us-ascii
\n";
$html .= "Subject: FYI-- $date\n";

$html .= "Priority: $priority\n\n"; # ---> here I'm trying to change
email priority

$html .= "<CENTER><HR>";
$html .= "<H1><FONT color=\"blue\">FYI -- $date</FONT></H1>\n";
$html .= "<HR></CENTER>";

open ( MAIL, "|/usr/bin/mail $email") or die;
print MAIL $html;
close ( MAIL);

Thank you in advance,
--Simon
simon.greenberg [ Do, 10 Januar 2008 20:02 ] [ ID #1904904 ]

Re: How to send email from perl-script with different priorities : normal or high

On 2008-01-10, sg <simon.greenberg [at] gmail.com> wrote:
>
> I'm trying to send email from my perl-script with different
> priorities : normal or high.
> For some reasons, I'm not going to use any perl-module like
> MIME::Lite.
>
> $email = "my.email\ [at] isp.com";
> $priority = 'high';
>
> $html = "MIME-Version: 1.0\nContent-Type: text/html\; charset=us-ascii
> \n";
> $html .= "Subject: FYI-- $date\n";
>
> $html .= "Priority: $priority\n\n"; # ---> here I'm trying to change
> email priority
>
> $html .= "<CENTER><HR>";
> $html .= "<H1><FONT color=\"blue\">FYI -- $date</FONT></H1>\n";
> $html .= "<HR></CENTER>";
>
> open ( MAIL, "|/usr/bin/mail $email") or die;
> print MAIL $html;
> close ( MAIL);

Do you realize that $html is entirely in the body of your message? You
can't set headers like this. If you're not going to use MIME::Lite, you
might consider using a module like Net::SMTP, where you construct the
whole message, including headers. (You also won't be dependent on the
behavior of /usr/bin/mail, which does vary across implementations.)

--keith


--
kkeller-usenet [at] wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
Keith Keller [ Do, 10 Januar 2008 21:01 ] [ ID #1904906 ]

Re: How to send email from perl-script with different priorities: normal or high

sg wrote:
> I'm trying to send email from my perl-script with different
> priorities : normal or high.

<snip>

> open ( MAIL, "|/usr/bin/mail $email") or die;

Try sendmail instead of mail:

open MAIL, "|/usr/sbin/sendmail -t $email" or die $!;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson [ Do, 10 Januar 2008 21:54 ] [ ID #1904908 ]

Re: How to send email from perl-script with different priorities :

On Jan 10, 12:54=A0pm, Gunnar Hjalmarsson <nore... [at] gunnar.cc> wrote:
> sg wrote:
> > I'm trying to send email from my perl-script with different
> > priorities : normal or high.
>
> <snip>
>
> > open =A0( MAIL, "|/usr/bin/mail $email") or die;
>
> Try sendmail instead of mail:
>
> open MAIL, "|/usr/sbin/sendmail -t $email" or die $!;
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl

Thank you all for support. Script works now. What is really important:

1. Format !!! $html .=3D "X-Priority: 1 (Highest)"."\n\n";

2. Both, /usr/bin/mail and /usr/sbin/mail -t are correctly
interpreting "HIGH" priopity parameter.

Cheers,
--Simon
simon.greenberg [ Do, 10 Januar 2008 23:50 ] [ ID #1904911 ]

Re: How to send email from perl-script with different priorities: normal or high

sg wrote:
> On Jan 10, 12:54 pm, Gunnar Hjalmarsson <nore... [at] gunnar.cc> wrote:
>> sg wrote:
>>>
>>> open ( MAIL, "|/usr/bin/mail $email") or die;
>>
>> Try sendmail instead of mail:
>>
>> open MAIL, "|/usr/sbin/sendmail -t $email" or die $!;
>
> 2. Both, /usr/bin/mail and /usr/sbin/mail -t are correctly
> interpreting "HIGH" priopity parameter.

[guess you meant to say: /usr/sbin/sendmail]

Funny, I thought that Keith was right in that 'mail' doesn't allow
message headers to be set the way you described.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson [ Fr, 11 Januar 2008 00:27 ] [ ID #1904913 ]

Re: How to send email from perl-script with different priorities : normal or high

On 2008-01-10, Gunnar Hjalmarsson <noreply [at] gunnar.cc> wrote:
>
> Funny, I thought that Keith was right in that 'mail' doesn't allow
> message headers to be set the way you described.

Maybe the OP's does. Mine doesn't. That's also why I said that
/usr/bin/mail varies wildly, and Net::SMTP is a better choice. Using
sendmail is better than using mail, but there's no guarantee that the
system has sendmail. If the script isn't meant to be used on another
machine, fine, but it always seems to happen to me that a script I never
meant for another machine always ends up on another machine.

--keith


--
kkeller-usenet [at] wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information
Keith Keller [ Fr, 11 Januar 2008 01:10 ] [ ID #1905768 ]

Re: How to send email from perl-script with different priorities :

On Jan 10, 3:27=A0pm, Gunnar Hjalmarsson <nore... [at] gunnar.cc> wrote:
> sg wrote:
> > On Jan 10, 12:54 pm, Gunnar Hjalmarsson <nore... [at] gunnar.cc> wrote:
> >> sg wrote:
>
> >>> open =A0( MAIL, "|/usr/bin/mail $email") or die;
>
> >> Try sendmail instead of mail:
>
> >> open MAIL, "|/usr/sbin/sendmail -t $email" or die $!;
>
> > 2. Both, /usr/bin/mail and /usr/sbin/mail -t are correctly
> > interpreting "HIGH" priopity parameter.
>
> [guess you meant to say: /usr/sbin/sendmail]
>
> Funny, I thought that Keith was right in that 'mail' doesn't allow
> message headers to be set the way you described.
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl

yes, you are right - It is a typo - should be /usr/sbin/sendmail

Thank you
simon.greenberg [ Fr, 11 Januar 2008 22:34 ] [ ID #1905793 ]
Perl » comp.lang.perl.misc » How to send email from perl-script with different priorities : normal

Vorheriges Thema: Testing CGI.pm-using code
Nächstes Thema: Using CPAN "lightweight"