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

Hello: I am using NET::SMTP to send email from my perl application. I need to time stamp the mails with a proper timezone where the receipent is. If the server is at CST and the time is 10 A.M the email receipent is in EST, then he should see the email with time stamp as 11 A.M. Since I know the receipent is in EST can I tell NET::SMTP to set the time as 11 A.M. I have seen some applicaitons sending timestamp in GMT using NET::SMTP modules in Java. Any help with code sample would be apprecaited. Thanks

Replies are listed 'Best First'.
Re: Using NET::SMTP
by polettix (Vicar) on May 18, 2005 at 16:38 UTC
    I would expect that the mail client should be able to cope with a correctly formatted timestamp, whatever it is configured (UTC or CST). so I would not waste time with it.

    I've never used it, but in my understanding Net::SMTP is a bit too low-level to have an explicit handling of the timestamp. From one of the examples

    #!/usr/local/bin/perl -w use Net::SMTP; $smtp = Net::SMTP->new('mailhost'); $smtp->mail($ENV{USER}); $smtp->to('postmaster'); $smtp->data(); $smtp->datasend("To: postmaster\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit;
    I see that you basically have to datasend() both headers and body, so why don't you put the timestamp using a Date: header? Something like:
    #!/usr/local/bin/perl -w use Net::SMTP; $smtp = Net::SMTP->new('mailhost'); $smtp->mail($ENV{USER}); $smtp->to('postmaster'); $smtp->data(); $smtp->datasend("To: postmaster\n"); $smtp->datasend("Date: Mon, 5 Jul 2004 11:35:36 +0200 (MEST)\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit;

    OTOH, if you're not telling the whole story and you're using some other module to build up your e-mail, like something in the MIME namespace, you probably have to look there for a way of setting the message date.

    Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

    Don't fool yourself.
Re: Using NET::SMTP
by Fang (Pilgrim) on May 18, 2005 at 16:40 UTC

    I would say this kind of work should be made by some other module. Searching CPAN for 'timezone' gives more than one result, as always. Your solution is probably in one of them.