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

Hello Perl Monks

I have multiple files I want to send to multiple emails. One file goes to one email recipient. I have StrawberryPerl 5.20.1.1 (64bit) on Windows 7 (64 bit). I have Mail::Sender installed. I copied the following code from, actually, I've looked at so many sites I forget where I copied it from. SMTP, To and From are real and will be used for my testing purposes.

#!/usr/local/bin/perl -w use Mail::Sender; $sender = {}; if ($sender->MailMsg({ smtp => 'ECMAIL7.internal.lacoe.edu', from => 'mansell_steven@lacoe.edu', to =>'sgmansell@gmail.com', subject => 'this is a test', msg => "Hi Steve.\nHow are you?" }) < 0) { print "if must be less than 0\n"; die "$Mail::Sender::Error\n"; } print "Mail sent OK."

I get this error

Can't call method "MailMsg" on unblessed reference at email_code.pl line 5.

I am not familiar with methods so I'm not sure what to do at this point.

1. Is there a way to send email without using methods? or do I need to learn methods?

2. Is there a way to test if I'm able to send an email through the Exchange server?

Thanks,

Steve

Replies are listed 'Best First'.
Re: email through Exchange server using StrawberryPerl
by roboticus (Chancellor) on Sep 30, 2014 at 18:56 UTC

    sgmansell:

    You created an empty hash reference, and then tried to call its MailMsg method. It doesn't have such a method. You need an object with that method. As shown in the synopsis in the documentation, you should be able to do it like:

    $sender = new Mail::Sender();

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thank you roboticus, that solved the "method" problem. Now I get

      'connect() failed:

      Does this mean the code couldn't get through port 25? Do I now need to talk to my company's mail server IT people to find out the parameters to get out?

        'connect() failed:

        The more important part of the error message is probably after the colon...

        Exchange can speak SMTP on port 25. Might be requiring authentication (user name and password). Depends on how it is configured.

        Might as well be a typo in the host name or something completely different...

        Read the complete error message - at least the part of it that consists of words :-)

        Even if you overcome this connect error, the next hurdle might be "relaying denied", and after you solved that, maybe comes "unknown recipient". So, at least in the "relaying denied" case, you will have to ask your IT people.

        sgmansell:

        Yes, that's what it means. As soonix states, the message after the colon should give you (or your EMail administrator) some further information on it. Because of the spam problem, many places lock out port 25, require authentication and/or alternate protocols. You'll definitely want to talk with your mail server IT team to help figure out what you need to do.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.