Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How does 'mail' program works

1 view
Skip to first unread message

Nishant Shah

unread,
Jan 30, 1999, 3:00:00 AM1/30/99
to
hello

i am writing a perl program which uses pipe to send mail to many persons.
Now i am able to send the mails but without subject.
Is there any 'command line' option with mail program which allows me to
write the subject field. Or is there any option in Perl to do so.

Please help me out
Thx
-Nishant

Neil Rickert

unread,
Jan 30, 1999, 3:00:00 AM1/30/99
to
Nishant Shah <nish...@usc.edu> writes:

>i am writing a perl program which uses pipe to send mail to many persons.
>Now i am able to send the mails but without subject.
>Is there any 'command line' option with mail program which allows me to
>write the subject field. Or is there any option in Perl to do so.

'mailx' has a '-s' option for the subject line.

An alternative is to build the message in a temp file, and put the
"Subject:" line there yourself.


Abigail

unread,
Jan 31, 1999, 3:00:00 AM1/31/99
to
Nishant Shah (nish...@usc.edu) wrote on MCMLXXVIII September MCMXCIII in
<URL:news:Pine.GSO.4.02.99013...@nunki.usc.edu>:
{}
{} Is there any 'command line' option with mail program which allows me to
{} write the subject field.

That's not a Perl question. Use the appropriate group for the mail
program you are using.

Abigail
--
perl -wlpe '}{$_=$.' file # Count the number of lines.

logan...@yahoo.com

unread,
Jan 31, 1999, 3:00:00 AM1/31/99
to
In article <Pine.GSO.4.02.99013...@nunki.usc.edu>,

Nishant Shah <nish...@usc.edu> wrote:
> i am writing a perl program which uses pipe to send mail to many persons.
> Now i am able to send the mails but without subject.
> Is there any 'command line' option with mail program which allows me to
> write the subject field. Or is there any option in Perl to do so.

Probably the most portable way among most Unix systems is to send the
message directly with sendmail. You'd just create an RFC-822 compliant
message, and then send it straight to sendmail.

Example:

sub sendamessage
{
local ($from, $to, $subject, $body) = @_;

if (!open (SENDMAIL, "| /usr/lib/sendmail -t"))
{
warn "Can't open pipe to sendmail because $!\n";
return 1;
}

print SENDMAIL "From: ", $from, "\n";
print SENDMAIL "To: ", $to, "\n";
print SENDMAIL "Subject: ", $subject, "\n";
print SENDMAIL "\n";
print SENDMAIL $body;
print SENDMAIL ".\n";

if (!close (SENDMAIL))
{
warn "sendmail failed because $!\n";
return 2;
}
}

&sendamessage ("m...@email.address",
"us...@who.wants.an.email",
"this is the email you wanted!",
"Here is some text.\nAren't you thrilled?\n");

This code isn't perfect because (1) it's completely untested (should work,
though) and (2) it can produce messages that don't conform to RFC-822
because it doesn't wrap header lines if they are too long.

Note: the above code was written by me, and I grant everyone permission
to use, copy, and modify it with the exception that permission is not
granted to use it in any part of the process of distributing bulk email.
Also, Microsoft or any employee of Microsoft is explicitly forbidden from
using any or all of the code.

- Logan

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

Jonathan Feinberg

unread,
Jan 31, 1999, 3:00:00 AM1/31/99
to logan...@yahoo.com
logan...@yahoo.com writes:

> local ($from, $to, $subject, $body) = @_;

Why use global variables? Use my(), not local(). See a recent Tom
Christiansen post for justification of this advice.

> warn "Can't open pipe to sendmail because $!\n";
> return 1;

It's common practice to return a false value when something fails.

> print SENDMAIL "From: ", $from, "\n";

If you're using double-quotes, you might as well really use them:

print SENDMAIL "From: $from\n";

Furthermore, since you're not doing any processing between calls to
print(), you might as well use a here doc, which makes the code
clearer IMO (and certainly more efficient).

print SENDMAIL <<"LAFFA_WHILE_YOU_CAN_MONKEY_BOY";
From: $from
To: $to
Subject $subject

$body
.
LAFFA_WHILE_YOU_CAN_MONKEY_BOY

Yours in unsolicited advice,
--
Jonathan Feinberg j...@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf

Stephen J. Tremblett

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
abi...@fnx.com (Abigail) writes:

>Nishant Shah (nish...@usc.edu) wrote on MCMLXXVIII September MCMXCIII in
><URL:news:Pine.GSO.4.02.99013...@nunki.usc.edu>:
>{}

>{} Is there any 'command line' option with mail program which allows me to
>{} write the subject field.

>That's not a Perl question. Use the appropriate group for the mail
>program you are using.


The time/effort/bandwidth/oxygen you wasted in posting that comment
could just as well have been used to say 'mail -s [subject]'. Even
funnier is that your rude enforcement of netiquette resulted in a
crosspost to comp.unix.questions. Thus I say "That's not a UNIX
question. Use the appropriate group for your stingy comment
(comp.dev.null)."

Have a nice day :)

--
-=> Steve Tremblett
-=> Memorial University Computer Science
-=> s...@cs.mun.ca; www.cs.mun.ca/~sjt

0 new messages