sending email from perl using a pipe and mailx - Perl

This is a discussion on sending email from perl using a pipe and mailx - Perl ; #!/usr/bin/perl # the main user to send the email to $recip = 'mainuser@domain.org'; # a comma separated list of users to CC the email too $cclist = 'ccuser1@domain.org,ccuser2@domain.org'; # open a pipe to the mailx utility and feed it a ...

+ Reply to Thread
Results 1 to 6 of 6

sending email from perl using a pipe and mailx

  1. Default sending email from perl using a pipe and mailx

    #!/usr/bin/perl

    # the main user to send the email to
    $recip = 'mainuser@domain.org';

    # a comma separated list of users to CC the email too
    $cclist = 'ccuser1@domain.org,ccuser2@domain.org';

    # open a pipe to the mailx utility and feed it a subject along with
    # recipients and the cclist
    open (FI, "|/usr/bin/mailx -s 'TEST: New email message' $recip -c
    $cclist");

    # send the body of the email message and close.
    # note: the email is not sent until the pipe is closed.
    printf (FI "blah\nblah blah\n");
    close (FI);

  2. Default Re: sending email from perl using a pipe and mailx

    bl8n8r <bl8n8r@gmail.com> wrote in
    news:453ccec8-946e-48ea-ae92-827b8b5d0461@
    59g2000hsb.googlegroups.com
    :

    > #!/usr/bin/perl
    >
    > # the main user to send the email to
    > $recip = 'mainuser@domain.org';
    >
    > # a comma separated list of users to CC the email too
    > $cclist = 'ccuser1@domain.org,ccuser2@domain.org';
    >
    > # open a pipe to the mailx utility and feed it a subject along
    > with # recipients and the cclist
    > open (FI, "|/usr/bin/mailx -s 'TEST: New email message' $recip -c
    > $cclist");
    >
    > # send the body of the email message and close.
    > # note: the email is not sent until the pipe is closed.
    > printf (FI "blah\nblah blah\n");
    > close (FI);


    Do you have a question?

    Sinan

    --
    A. Sinan Unur <1usa@llenroc.ude.invalid>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/

  3. Default Re: sending email from perl using a pipe and mailx

    A. Sinan Unur wrote:
    > bl8n8r <bl8n8r@gmail.com> wrote in
    > news:453ccec8-946e-48ea-ae92-827b8b5d0461@
    > 59g2000hsb.googlegroups.com
    >>

    >
    >> #!/usr/bin/perl
    >>
    >> # the main user to send the email to
    >> $recip = 'mainuser@domain.org';
    >>
    >> # a comma separated list of users to CC the email too
    >> $cclist = 'ccuser1@domain.org,ccuser2@domain.org';
    >>
    >> # open a pipe to the mailx utility and feed it a subject along
    >> with # recipients and the cclist
    >> open (FI, "|/usr/bin/mailx -s 'TEST: New email message' $recip -c
    >> $cclist");
    >>
    >> # send the body of the email message and close.
    >> # note: the email is not sent until the pipe is closed.
    >> printf (FI "blah\nblah blah\n");
    >> close (FI);

    >
    > Do you have a question?


    Why assume everything that is posted is always going to be a question?
    Looks to me like someone was just sharing some code they had written. It
    may not be the most complex of programs, but hey, everyone's gotta'
    start somewhere.

    --
    szr



  4. Default Re: sending email from perl using a pipe and mailx

    At 2008-04-18 10:05AM, "bl8n8r" wrote:
    > #!/usr/bin/perl
    >
    > # the main user to send the email to
    > $recip = 'mainuser@domain.org';
    >
    > # a comma separated list of users to CC the email too
    > $cclist = 'ccuser1@domain.org,ccuser2@domain.org';
    >
    > # open a pipe to the mailx utility and feed it a subject along with
    > # recipients and the cclist
    > open (FI, "|/usr/bin/mailx -s 'TEST: New email message' $recip -c
    > $cclist");
    >
    > # send the body of the email message and close.
    > # note: the email is not sent until the pipe is closed.
    > printf (FI "blah\nblah blah\n");
    > close (FI);


    If you're looking for feedback:

    #!/usr/bin/perl

    use strict;
    use warnings;

    my $to = 'mainuser@domain.org';
    my $cc = 'ccuser1@domain.org,ccuser2@domain.org';
    my $subj = 'TEST: New email message';

    open my $pipe, '|-', '/usr/bin/mailx', '-s', $subj, '-c', $cc, $to
    or die "can't open pipe to mailx: $!\n";

    print $pipe $body;

    close $pipe;

    die "mailx exited with a non-zero status: $?\n" if $?;

    --
    Glenn Jackman
    "If there is anything the nonconformist hates worse than a conformist,
    it's another nonconformist who doesn't conform to the prevailing
    standard of nonconformity." -- Bill Vaughan

  5. Default Re: sending email from perl using a pipe and mailx

    bl8n8r <bl8n8r@gmail.com> wrote:
    >#!/usr/bin/perl


    Missing
    use strict;
    use warnings;

    ># the main user to send the email to
    >$recip = 'mainuser@domain.org';
    >
    ># a comma separated list of users to CC the email too
    >$cclist = 'ccuser1@domain.org,ccuser2@domain.org';
    >
    ># open a pipe to the mailx utility and feed it a subject along with
    ># recipients and the cclist
    >open (FI, "|/usr/bin/mailx -s 'TEST: New email message' $recip -c
    >$cclist");


    Missing error handling.
    Would be better to use 3-argument form of open.

    ># send the body of the email message and close.
    ># note: the email is not sent until the pipe is closed.
    >printf (FI "blah\nblah blah\n");


    Why are you using printf() when you don't have a format specifier?

    >close (FI);


    jue

  6. Default Re: sending email from perl using a pipe and mailx

    Quote Originally Posted by usenet View Post
    bl8n8r <bl8n8r@gmail.com> wrote:
    >#!/usr/bin/perl


    Missing
    use strict;
    use warnings;

    ># the main user to send the email to
    >$recip = 'mainuser@domain.org';
    >
    ># a comma separated list of users to CC the email too
    >$cclist = 'ccuser1@domain.org,ccuser2@domain.org';
    >
    ># open a pipe to the mailx utility and feed it a subject along with
    ># recipients and the cclist
    >open (FI, "|/usr/bin/mailx -s 'TEST: New email message' $recip -c
    >$cclist");


    Missing error handling.
    Would be better to use 3-argument form of open.

    ># send the body of the email message and close.
    ># note: the email is not sent until the pipe is closed.
    >printf (FI "blah\nblah blah\n");


    Why are you using printf() when you don't have a format specifier?

    >close (FI);


    jue
    --------------


    Hi

    I use that sentence and work

    VAR=`tail -f /var/log/messages | grep shutdown`
    cmd = `echo \"My system down $VAR\" | mailx -s \"System Down\" my_account\@mydomain.com`;

    I hope work for you

    Cya

+ Reply to Thread