in reply to How to send mail (with attachments) from a Winx64 box

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

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

Replies are listed 'Best First'.
Re^2: How to send mail (with attachments) from a Winx64 box
by keszler (Priest) on Nov 04, 2009 at 13:24 UTC
    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.

Re^2: How to send mail (with attachments) from a Winx64 box
by wol (Hermit) on Nov 04, 2009 at 13:57 UTC
    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". ;-)