in reply to Strange Situation with Net::SMTP

Don’t see a reason why your code does not work, believe your code is not the exact copy of your original one.

As for the difference between “ and ‘, I made this demo for you. To play with it, first replace the pseudo email server and address with your real ones, then uncomment one of the four commented lines, and see what happens. Explanations are beside those lines.

use Net::SMTP; $smtp = Net::SMTP->new('mail.telus.net'); $smtp->mail('p@abc.com'); #$smtp->to('p@abc.com'); #this one works, assume p@abc.com exists #$smtp->to("p@abc.com"); #this one doesn't work, as Perl will try to r +esolve @abc for you #$smtp->to('p\@abc.com'); #this one does not work, as Perl see the add +ress as p\@abc.com (assume that this address does not exist) #$smtp->to("p\@abc.com"); #this one works, as we escaped that @ $smtp->data(); $smtp->datasend("To: Peter\n"); $smtp->datasend("\n"); $smtp->datasend("test\n"); $smtp->dataend(); $smtp->quit;

Replies are listed 'Best First'.
Re: Re: Strange Situation with Net::SMTP
by CodeJunkie (Monk) on Mar 25, 2003 at 21:05 UTC

    Thanks for the explanation of the " " and ' ', that makes a lot more sense now.

    Don't seem to be able to get the code above to work though, it just hangs for about 5 seconds, then I get this message 'Can't call method "mail" on an undefined value at mailme.pl line 6'

    What does the $smtp->mail('me@foo.com'); line actually do then? Compared to the $smtp->to('me@foo.com');?

      I tested it before I post, as I always do. I believe the problem is that you didn't replace the email server name and email address with real ones.

      The error you got basically means that $smtp is undef. I believe that is because you didn't change my dummy server name to your real one, so Perl can not establish the SMTP connection.
      Check out the docs for Net::SMTP and RFC 821 for the full answer but basically. $smtp->mail('me@foo.com'); is From:me@foo.com
      and $smtp->to('me@foo.com'); is....well To:me@foo.com