Hi Friends

I have written a perl script which sends an email on Windows using NetSMTP.

#!C:/cygwin/bin/perl
#print "Hello world";
use Net::SMTP;
use strict;
my $smtpserver = '10.154.118.140';
#my $smtpserver = '127.0.0.1';
my $smtpuser = 'myname';
my $fromemail = 'myname@mycompany.com';

    my $smtp = Net::SMTP-> new($smtpserver, Timeout => 10);
    $smtp-> mail($smtpuser);
    $smtp-> to('friend@mycompany.com');
    $smtp-> data();
    $smtp-> datasend("To: blblb\@blblbl.cz\n");
    $smtp-> datasend("From: psmejkal\@tesco.cz\n");
    $smtp-> datasend("\n");
    $smtp-> datasend("test\n");
    $smtp-> dataend();
    $smtp-> quit;

While executing the program Im getting the following error

Can't call method "mail" on an undefined value at ./mail.pl line 11.

Any clue?

Could it have anything to do with the fact that $smtpuser is not a valid email address? It's only the string 'myname'. The variable $fromemail is your email address.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.