Problem with sending mail using perl

Discussion in 'Perl Misc' started by Kimi, Sep 5, 2007.

  1. Kimi

    Kimi Guest

    While trying to use this simple unix command to send mail using perl

    #!/usr/bin/perl
    my $output =`echo Mailbody | mail `;

    I am facing a strange issue where "" gets converted to
    "" and the mail is sent to it. Could some
    one throw pointers to get rid of the issue.

    The above unix code works perfectly well when executed separately and
    send mail to

    Thanks in Advance,
    Fahad
     
    Kimi, Sep 5, 2007
    #1
    1. Advertising

  2. On Sep 5, 11:12 am, Kimi <> wrote:
    > While trying to use this simple unix command to send mail using perl
    >
    > #!/usr/bin/perl
    > my $output =`echo Mailbody | mail `;
    >
    > I am facing a strange issue where "" gets converted to
    > "" and the mail is sent to it. Could some
    > one throw pointers to get rid of the issue.
    >
    > The above unix code works perfectly well when executed separately and
    > send mail to
    >
    > Thanks in Advance,
    > Fahad


    Put a "\" in front of the "@"

    #!/usr/bin/perl
    my $output =`echo Mailbody | mail afa...\@VSNL.com`;
     
    Benoit Lefebvre, Sep 5, 2007
    #2
    1. Advertising

  3. Kimi

    Kimi Guest

    On Sep 5, 8:14 pm, Benoit Lefebvre <> wrote:
    > On Sep 5, 11:12 am, Kimi <> wrote:
    >
    > > While trying to use this simple unix command to send mail using perl

    >
    > > #!/usr/bin/perl
    > > my $output =`echo Mailbody | mail `;

    >
    > > I am facing a strange issue where "" gets converted to
    > > "" and the mail is sent to it. Could some
    > > one throw pointers to get rid of the issue.

    >
    > > The above unix code works perfectly well when executed separately and
    > > send mail to

    >
    > > Thanks in Advance,
    > > Fahad

    >
    > Put a "\" in front of the "@"
    >
    > #!/usr/bin/perl
    > my $output =`echo Mailbody | mail afa...\@VSNL.com`;



    Thanks Benoit, That was helpful. But Is it how mail ids are supposed
    to be used in perl in general. Suppose I am assigning the mail id to a
    variable and want to use it,

    Should it be again like,

    #!/usr/bin/perl
    $mail_id="afahad\@VSNL.com";
    my $output =`echo Mailbody | mail $mail_id`;

    Or is there a better way?

    Thanks in Advance,
    Kimi
     
    Kimi, Sep 5, 2007
    #3
  4. Kimi

    Ben Morrow Guest

    Quoth Kimi <>:
    > On Sep 5, 8:14 pm, Benoit Lefebvre <> wrote:
    > > On Sep 5, 11:12 am, Kimi <> wrote:
    > >
    > > > While trying to use this simple unix command to send mail using perl

    > >
    > > > #!/usr/bin/perl
    > > > my $output =`echo Mailbody | mail `;

    > >
    > > > I am facing a strange issue where "" gets converted to
    > > > "" and the mail is sent to it. Could some
    > > > one throw pointers to get rid of the issue.

    > >
    > > > The above unix code works perfectly well when executed separately and
    > > > send mail to

    > >
    > > Put a "\" in front of the "@"
    > >
    > > #!/usr/bin/perl
    > > my $output =`echo Mailbody | mail afa...\@VSNL.com`;

    >
    > Thanks Benoit, That was helpful. But Is it how mail ids are supposed
    > to be used in perl in general. Suppose I am assigning the mail id to a
    > variable and want to use it,


    @VSNL is a variable. Variables interpolate in "" strings. If you had put

    use strict;
    use warnings;

    at the top of your script, Perl would have told you what was wrong.

    > Should it be again like,
    >
    > #!/usr/bin/perl
    > $mail_id="afahad\@VSNL.com";
    > my $output =`echo Mailbody | mail $mail_id`;
    >
    > Or is there a better way?


    This is a perfectly good way, yes. Slightly clearer might be

    $mail_id = '';

    note that I no longer have to use \@ as single quotes don't expand
    variables.

    Ben
     
    Ben Morrow, Sep 5, 2007
    #4
  5. Kimi

    Kimi Guest

    On Sep 5, 9:48 pm, Ben Morrow <> wrote:
    > Quoth Kimi <>:
    >
    >
    >
    > > On Sep 5, 8:14 pm, Benoit Lefebvre <> wrote:
    > > > On Sep 5, 11:12 am, Kimi <> wrote:

    >
    > > > > While trying to use this simple unix command to send mail using perl

    >
    > > > > #!/usr/bin/perl
    > > > > my $output =`echo Mailbody | mail `;

    >
    > > > > I am facing a strange issue where "" gets converted to
    > > > > "" and the mail is sent to it. Could some
    > > > > one throw pointers to get rid of the issue.

    >
    > > > > The above unix code works perfectly well when executed separately and
    > > > > send mail to

    >
    > > > Put a "\" in front of the "@"

    >
    > > > #!/usr/bin/perl
    > > > my $output =`echo Mailbody | mail afa...\@VSNL.com`;

    >
    > > Thanks Benoit, That was helpful. But Is it how mail ids are supposed
    > > to be used in perl in general. Suppose I am assigning the mail id to a
    > > variable and want to use it,

    >
    > @VSNL is a variable. Variables interpolate in "" strings. If you had put
    >
    > use strict;
    > use warnings;
    >
    > at the top of your script, Perl would have told you what was wrong.
    >
    > > Should it be again like,

    >
    > > #!/usr/bin/perl
    > > $mail_id="afahad\@VSNL.com";
    > > my $output =`echo Mailbody | mail $mail_id`;

    >
    > > Or is there a better way?

    >
    > This is a perfectly good way, yes. Slightly clearer might be
    >
    > $mail_id = '';
    >
    > note that I no longer have to use \@ as single quotes don't expand
    > variables.
    >
    > Ben



    Thanks Ben.

    -Kimi
     
    Kimi, Sep 6, 2007
    #5
    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. Replies:
    4
    Views:
    55,486
  2. Replies:
    0
    Views:
    1,375
  3. Luke
    Replies:
    2
    Views:
    4,721
    Nigel Wade
    Mar 15, 2007
  4. Lokesh

    Sending mail using System.web.mail

    Lokesh, Jan 27, 2006, in forum: ASP .Net Security
    Replies:
    1
    Views:
    161
    Li-fan Chen
    Feb 16, 2006
  5. martin smith
    Replies:
    3
    Views:
    336
    Jeff Cochran
    Mar 21, 2005
Loading...

Share This Page