• Как узнать имя текущий функции?

    strongmonkey
    @strongmonkey Автор вопроса
    Решено.

    package method;
    use strict;
    use warnings FATAL => 'all';
    
    my @list_method = qw(method_1 method_2 method_3);
    
    sub new {
      my ($class, $options) = @_;
      __genereate_code();
    
      return bless {}, $class;
    }
    
    sub __make_method {
      my ( $method, $code, $pkg ) = @_;
    
      $pkg ||= caller();
      no strict 'refs';
      *{ $pkg . "::$method" } = $code;
    }
    
    sub __genereate_code {
      foreach my $element (@list_method)
      {
        __make_method($element, sub { return $element; } );
      }
    }
    
    1;
    Ответ написан
    Комментировать
  • Как по средствам perl отправить email?

    strongmonkey
    @strongmonkey Автор вопроса
    Net::SMTP_auth последовал вашему совету использую Net::SMTP_auth. Лог изменился, вроде пароль серверу переда. Но ошибка та же.

    Process started >>>
    Net::SMTP_auth>>> Net::SMTP_auth(0.08)
    Net::SMTP_auth>>> Net::SMTP(2.34)
    Net::SMTP_auth>>> Net::Cmd(2.30)
    Net::SMTP_auth>>> Exporter(5.71)
    Net::SMTP_auth>>> IO::Socket::INET(1.35)
    Net::SMTP_auth>>> IO::Socket(1.38)
    Net::SMTP_auth>>> IO::Handle(1.35)
    Net::SMTP_auth=GLOB(0x32a7210)<<< 220 srvexcas2.bops.local Microsoft ESMTP MAIL Service ready at Wed, 23 Dec 2015 22:04:43 -0800
    Net::SMTP_auth=GLOB(0x32a7210)>>> EHLO localhost.localdomain
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-srvexcas2.bops.local Hello [172.20.14.75]
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-SIZE 37748736
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-PIPELINING
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-DSN
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-ENHANCEDSTATUSCODES
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-STARTTLS
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-X-ANONYMOUSTLS
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-AUTH NTLM
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-X-EXPS GSSAPI NTLM
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-8BITMIME
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-BINARYMIME
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250-CHUNKING
    Net::SMTP_auth=GLOB(0x32a7210)<<< 250 XRDST
    Net::SMTP_auth=GLOB(0x32a7210)>>> AUTH NTLM TlRMTVNTUAABAAAAB6IAAAMAAwAgAAAAAAAAAAMAAABkd2g=
    Net::SMTP_auth=GLOB(0x32a7210)<<< 334 TlRMTVNTUAACAAAACAAIADgAAAAFgoECHJxYyefK5M8AAAAAAAAAAI4AjgBAAAAABgOAJQAAAA9CAE8AUABTAAIACABCAE8AUABTAAEAEgBTAFIAVgBFAFgAQwBBAFMAMgAEABQAYgBvAHAAcwAuAGwAbwBjAGEAbAADACgAcwByAHYAZQB4AGMAYQBzADIALgBiAG8AcABzAC4AbABvAGMAYQBsAAUAFABiAG8AcABzAC4AbABvAGMAYQBsAAcACACm7t37ED7RAQAAAAA=
    Net::SMTP_auth=GLOB(0x32a7210)>>> TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAgACABwAAAABgAGAHgAAAAGAAYAfgAAAAAAAABEAAAABYKBAnG9ceiZyEyU3wCV8NOAfE8TH+/clRupP7yUlEceMUku8CHdpBvP/hrs861nYznZ/UIATwBQAFMAZAB3AGgAZAB3AGgA
    Net::SMTP_auth=GLOB(0x32a7210)<<< 535 5.7.3 Authentication unsuccessful
    <<< Process finished. (Exit code 1)
    ================ READY ================

    #! /usr/bin/perl -w
    
    sub send_mail {
    	use Net::SMTP_auth;
    	use Authen::SASL;
    	use Authen::NTLM;
    	use MIME::Base64;
    		
        my ($smtpserver, $to, $from, $msg, $subject, $apass) = @_;
        my $error;
        my $body;
        my $smtp;
        
        $body = "MIME-Version: 1.0\n"
            . "From: $from\n"
            . "To: $to \n"
            . "Subject: $subject\n\n" 
            . $msg . "\n"; 
     
    	eval { };
    	
        if (!ref($to))
        { 
            @$to = split(/[,;]\s*/, $to); 
        }
        if(!($smtp = Net::SMTP_auth->new($smtpserver, Debug => 1)))
        {
            return "Could not connect to SMTP Server: $smtpserver \n";
        }
    	if (length($apass) > 0)
    	{		
    		if(!($smtp->auth('NTLM', '', '')))
    		{
    			return $smtp->message(); 
    		}
    	}
        if (!($smtp->mail($from)))
        {
            return "Bad From, check your Ac count Information " . $smtp->message();
        }
        if (!($smtp->recipient(@$to)))
        {	
            return "Bad EmailTo " . $smtp->message();
        }
        
        $smtp->data($body);
        $smtp->quit;
        
        return 0;
    }
    Ответ написан
    Комментировать