in reply to Re^2: Getting Error "Unknown send method" when sending mail using MIME::Lite??
in thread Getting Error "Unknown send method" when sending mail using MIME::Lite??

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
  • Comment on Re^3: Getting Error "Unknown send method" when sending mail using MIME::Lite??

Replies are listed 'Best First'.
Re^4: Getting Error "Unknown send method" when sending mail using MIME::Lite??
by almut (Canon) on Feb 24, 2010 at 19:59 UTC

    Not sure what you're trying to point out.  Class methods don't need an object instance to be called upon.

    If you look at the implementation of MIME::Lite::send(),

    sub send { my $self = shift; my $meth = shift; if ( ref($self) ) { ### instance method: my ( $method, @args ); if (@_) { ### args; use them just this once $method = 'send_by_' . $meth; @args = @_; } else { ### no args; use defaults $method = "send_by_$Sender"; @args = @{ $SenderArgs{$Sender} || [] }; } $self->verify_data if $AUTO_VERIFY; ### prevents missing pa +rts! Carp::croak "Unknown send method '$meth'" unless $self->can($m +ethod); return $self->$method(@args); } else { ### class method: if (@_) { my @old = ( $Sender, @{ $SenderArgs{$Sender} } ); $Sender = $meth; $SenderArgs{$Sender} = [@_]; ### remaining args return @old; } else { Carp::croak "class method send must have HOW... arguments\ +n"; } } }

    you'll see that in the else branch (### class method), the send method to be set as default is stored in some global variable $Sender together with the arguments in $SenderArgs{$Sender}.

    Those values are then being used when send() is called as an instance method. What makes the program croak is that $self->can($method) is failing, because - apparently - there is no 'send_by_smtp' method in the OP's case.  I can't tell why, however — my version of MIME::Lite does have such a method.