Sachin has asked for the wisdom of the Perl Monks concerning the following question:

use strict; use MIME::Lite; # SendTo email id my $email = 'a@example.com'; MIME::Lite->send('smtp','example.com',Debug=>1) || die $!; # create a new MIME Lite based email my $msg = MIME::Lite->new ( Subject => "HTML email test", From => 'x@example.com', To => $email, Type => 'text/html', Data => '<H1>Hello</H1><br>This is a test email. Please visit our site <a href="http://cyberciti.biz/">online</a><hr>' ); $msg->send();

When i run this program it's give error "Unknown send method". Can you help me about this problem.

  • Comment on Getting Error "Unknown send method" when sending mail using MIME::Lite??
  • Download Code

Replies are listed 'Best First'.
Re: Getting Error "Unknown send method" when sending mail using MIME::Lite??
by keszler (Priest) on Feb 24, 2010 at 10:25 UTC
    Are you running this on Windows? According to the documentation:
    On Win32 systems the default setting is equivalent to:
    MIME::Lite->send("smtp");
    The assumption is that on Win32 your site/lib/Net/libnet.cfg file will be preconfigured to use the appropriate SMTP server. See below for configuring for authentication.
    If you're on Windows, is your libnet.cfg correctly configured? If not, there's your problem.

    If you're not on Windows, 'smtp' is not the right option for MIME::Lite->send

Re: Getting Error "Unknown send method" when sending mail using MIME::Lite??
by jethro (Monsignor) on Feb 24, 2010 at 09:18 UTC
    Throw away the line beginning with "MIME::Lite->send". That line makes no sense, you are trying to use send before having defined what to send. Note the "$msg->send" line at the end that does the right thing at the right time.

    UPDATE: Baah, wrong answer. MIME::Lite uses send as class method to specify the send method. Please ignore above. And -- to MIME::Lite for silly method name reuse.

Re: Getting Error "Unknown send method" when sending mail using MIME::Lite??
by Neighbour (Friar) on Feb 24, 2010 at 09:20 UTC
    Why are you (trying to) send out an email before constructing it?
    MIME::Lite->send('smtp','example.com',Debug=>1) || die $!;
    That doesn't seem properly placed.
    If you remove that line, and edit $msg->send(); to read
    $msg->send('smtp','example.com',Debug=>1) || die $!;
    things would go better.

      According to the docs:

      MIME::Lite->send()

      When used as a classmethod, this can be used to specify a different default mechanism for sending message.

      In other words, what the OP is trying to do is perfectly fine.

        In other words, what the OP is trying to do is perfectly fine.

        The issue is that a function is being called on an object that has not yet been instantiated. Once the ->new function has been called, the object is created, which then allows the send function to be called.
        /\ Sierpinski
Re: Getting Error "Unknown send method" when sending mail using MIME::Lite??
by sierpinski (Chaplain) on Feb 24, 2010 at 19:30 UTC
    Definitely the error is caused by trying to call a function before the calling object is defined. Object->new defines it, then Object->function is how you'd call the functions on that object.

    I agree completely, you've got redundant info there... delete the first ->send message, because later on you define all the parameters that the send function requires.
    /\ Sierpinski