sending email from perl using a pipe and mailx

Discussion in 'Perl Misc' started by bl8n8r, Apr 18, 2008.

  1. bl8n8r

    bl8n8r Guest

    #!/usr/bin/perl

    # the main user to send the email to
    $recip = '';

    # a comma separated list of users to CC the email too
    $cclist = ',';

    # 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);
     
    bl8n8r, Apr 18, 2008
    #1
    1. Advertising

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

    > #!/usr/bin/perl
    >
    > # the main user to send the email to
    > $recip = '';
    >
    > # a comma separated list of users to CC the email too
    > $cclist = ',';
    >
    > # 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 <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/
     
    A. Sinan Unur, Apr 18, 2008
    #2
    1. Advertising

  3. bl8n8r

    szr Guest

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

    >
    >> #!/usr/bin/perl
    >>
    >> # the main user to send the email to
    >> $recip = '';
    >>
    >> # a comma separated list of users to CC the email too
    >> $cclist = ',';
    >>
    >> # 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
     
    szr, Apr 18, 2008
    #3
  4. bl8n8r <> wrote:
    >#!/usr/bin/perl


    Missing
    use strict;
    use warnings;

    ># the main user to send the email to
    >$recip = '';
    >
    ># a comma separated list of users to CC the email too
    >$cclist = ',';
    >
    ># 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
     
    Jürgen Exner, Apr 18, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    504
    Jack Klein
    Nov 2, 2004
  2. Guest
    Replies:
    0
    Views:
    327
    Guest
    Sep 1, 2005
  3. aemi
    Replies:
    3
    Views:
    5,959
    Greg R. Broderick
    Jan 7, 2007
  4. rote
    Replies:
    8
    Views:
    796
  5. Replies:
    1
    Views:
    246
    Ben Morrow
    Jun 2, 2004
Loading...

Share This Page