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

Dear Learned Monks

I'm running (Active)Perl 5.10 on a Winx64 box (necessary due to SQL server) and I need to be able to mail out messages with attachments.

AFAIK there's no mail transfer agent (MTA) on the box and while I've looked around a few posts on Mail::Sendmail & MIME::Lite they either need MTAs or don't allow attachments.

I'm fully prepared to admit naivety here, but I can't seem to find an x64 solution anywhere. Any pointers anyone?

Thanks in advance

  • Comment on How to send mail (with attachments) from a Winx64 box

Replies are listed 'Best First'.
Re: How to send mail (with attachments) from a Winx64 box
by Corion (Patriarch) on Nov 04, 2009 at 13:15 UTC

    MIME::Lite only needs to know what mail server to contact, it doesn't need a local MTA.

      Even better. To get the mailserver, something like this (with your added sanity and error-checking):

      use strict; use Net::DNS; my ($domain) = $email_to =~ /@(.*)$/; my ($mailserver) = map { $_->exchange } sort { $a->preference <=> $b-> +preference } mx($domain);

      This gets the most preferred mailserver. Alternately, you might want to loop the array by preference, exiting on success.

      I've previously sent mail with attachments from Perl using MIME::Lite.

      I don't really know what MTAs are for. I don't think I used one.

      Given Corion's comment and my own ignorance, I recommend that you (the OP) try to go ahead with the MIME::Lite module.

      (I would post some of the code to show what I did, but it was in a previous job and I just don't have it any more.)

      --
      use JAPH;
      print JAPH::asString();

        I don't really know what MTAs are for. I don't think I used one.

        I'm sure you have used a Mail Transport Agent before, even multiple times. In fact, you use it every time you send an e-mail. It is what is commonly known as "mail server". The other thing commonly found in the E-Mail RFCs is a Mail User Agent, commonly known as "mail client". MIME::Lite is one of those clients when it uses SMTP to connect to a mail server. The system's sendmail program can also work as MUA / mail client, this happens when MIME::Lite calls sendmail.

        The examples shown in the MIME::Lite documentation are pretty good, they should get the OP started within a few minutes. The only problem of MIME::Lite is the sendmail mode, there is really no need to use sendmail at all, even on a Unix system. Unfortunately, some old versions of MIME::Lite insist on having a sendmail binary somewhere except on Windows, and they default to using sendmail instead of sending via SMTP.

        Whenever I use MIME::Lite, my code starts with something like MIME::Lite->send('smtp', $mailserver, Timeout=>60, AuthUser=>$user, AuthPass=>$pass); to switch to authenticated SMTP mode. Most times, I use a tiny wrapper around MIME::Lite that reads the application's configuration file for mail server, login and password, switches to SMTP, and sometimes adds some extra features to MIME::Lite. Last time I looked, MIME::Lite had some internal helper functions (not methods), so clean inheritance did not work too well, runtime patching was required for some extra features.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: How to send mail (with attachments) from a Winx64 box
by keszler (Priest) on Nov 04, 2009 at 13:05 UTC
    Use Net::DNS to look up the MX record for the email recipient(s), then Net::SMTP to that mailserver.

    Net::SMTP does not provide support for attachments, so you'll need MIME::Lite or similar to create the attachments first.