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

any perl module can do mail forwarding through SMTP server ? program is run in NT machine ... so ... no SENDMAIL i'm using Net::SMTP to send simple text mail and use MIME::Lite to send mail with attachments ... anyone could give me some advice if i wanna do mail forwarding ... ? THX
  • Comment on does MIME::Lite or Net::SMTP provide forward mail function ..... ANY OTHER OPTIONS ??

Replies are listed 'Best First'.
Re: does MIME::Lite or Net::SMTP provide forward mail function ..... ANY OTHER OPTIONS ??
by Corion (Patriarch) on Mar 11, 2001 at 16:03 UTC

    Your question is quite unclear. You can already send mail from your NT machine. The question is, where does your mail come from in the first place ?

    One option is a port of Sendmail for NT, so you might want to use it instead of a Perl script.

    If your mail server is Exchange, you will have to look into the MAPI programming interface, but you can't use the full MAPI capabilities from within Perl without some help from C. There is also a SMTP adapter for MAPI, which will allow you to send mail to Exchange via port 25 and the SMT Protocol.

Re: does MIME::Lite or Net::SMTP provide forward mail function ..... ANY OTHER OPTIONS ??
by BlueLines (Hermit) on Mar 11, 2001 at 17:46 UTC

    Corion is right. Your question is very unclear. I guess asking for a perl module/script to do mail forwarding is the equivalent of asking for a perl module to change a lightbulb. It could be done, but there exist easier ways. In most mail servers that run in a UNIX environment, simply having a file named ".forward" in your home directory would forward any mail to the contents of the file if they were an email address, or to a shell process that you could specify via |. I doubt there's something similar to this in the Win32 environment, but setting up mail forwarding on an Outlook server seems like it should be very trivial. So writing a script seems to be kind of pointless (in my opinion).

    But, assuming you really want to forward mail, you'd need to do the following:

    • Check to see if your account has gotten mail. You can telnet to the imap/pop port if you don't have the correct perl modules installed to talk.
    • Download any mail that you have recieved.
    • Scan the mail to make sure it's for you (and to block out anything you might not want forwarded).
    • Open up SMTP connection to some server, using the previously fetched email as the body of the message
    • Done. Now loop again. Endlessly.
    So as you can see, this is alot more work than it's worth. I agree that there's always more than one way to do things, but just because there's a harder way doesn't mean you have to take it.

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
      THX MATE ... um ... now i can get my mail ... and then i want to forward my mail to others ... so i try to collect the message of my mail ... however ... i odn't know how to filter my mail's headers to get the message body only ... could you teach me how to do so?
      THX MATE ... um ... now i can get my mail ... and then i want to forward my mail to others ... so i try to collect the message of my mail ... however ... i don't know how to filter my mail's headers so as to get the message body only ... could you teach me how to do so?
        Mail::Header for headers
        The message body depends on plain text\mime. If plain, then you can do it with no modules v. easily if you know what an email message looks like.

        $ perldoc perldoc
Re: does MIME::Lite or Net::SMTP provide forward mail function ...
by Coyote (Deacon) on Mar 12, 2001 at 02:40 UTC
    Are you looking for something like procmail? Procmail allows you to apply filtering and processing rules to incomming mail. With procmail, you can do things like forward all mail with a certain string in the title to another address, move mail comming from a mailing list to a specific folder, send mail that is not addressed directly to you (spam) to the trash and so on. Procmail is a UNIX utility, however Mail::Audit and Mail::Procmail provide similar functionality in pure perl. You can use these modules in conjunction to one of the mail client modules (i.e., Net::Pop3), a mailserver such as Mercury and NT's at command to simulate the functionality of procmail. Hope this helps.

    ----
    Coyote