Perhaps one of you has seen this and can help. I'm using Net::SMTP to send emails and loving it; except for one thing which i'm getting grief from one user about. The send time is wrong. It's running on a windows client, and could run on just about any version of windows. The SMTP example code shows the timezone as UTC, while i'm in EST (which also leads to a DST bonus question). This could potentially also run in India and or Germany, therefore I need to check the host system for the timezone. So because it's available in most versions of windows i'm using wmic to get the time which gives "(UTC-05:00) Eastern Time (US & Canada)" from which i take -0500. But still the send time of the email is an hour after i received it (instant). Any suggestions? I've tried looking at the SMTP spec and it should accept -0500 time format. Thank you.

I posted some extra code in case anyone else is trying to use SMTP and attach files and do email with HTML. This is part of a sub.

Updated with suggestion in case anyone wants this.

my $subject = "Test Complete for station $station_num"; my @addresses = split(",",$emailconfig{"addresses$diagmode"}); for (my $a = 0; $a < @addresses; $a++) { if ($addresses[$a] !~ m/\@/) { $addresses[$a] .= "\@".$emailconfig{domain}; } } my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me(); $year += 1900; my $mytimezone = qx"wmic timezone get Description"; #(UTC-05:00) E +astern Time (US & Canada) my $timezone = "EST"; #default foreach my $line (split("\n",$mytimezone)) { if ($line =~ m/\([UG][TM][CT]([+-]\d+:\d+)\)/) { $timezone = $1; $timezone =~ s/://; last; } } print "TIMEZONE: $timezone\n"; #Create an RFC compliant time stamp my $Date = sprintf("%s, %02d %3s %04d %02d:%02d:%02d %5s",$dayofwe +ek[$wday],$mday,$monthnames[$mon],$year,$hour - $isdst,$min,$sec,$tim +ezone); my $smtp = Net::SMTP->new(Host=>$emailconfig{server}, Hello=>$emai +lconfig{domain}, Timeout=>120, Debug=>0); if (not defined $smtp) { croak "Unable to connect to mailhost [$emailconfig{server}]"; } else { $smtp->mail("NOREPLY\@ami.com"); $smtp->to(@addresses); #start data to server $smtp->data(); #HEADER $smtp->datasend("From: NOREPLY\@$emailconfig{domain}\n"); $smtp->datasend("To: ".join(",",@addresses)."\n"); $smtp->datasend("Reply-To: NOREPLY\@$emailconfig{domain}\n"); $smtp->datasend("Date: $Date\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-Type: multipart/mixed; boundary= \"*B +CKTR*\"\n"); $smtp->datasend("\n"); #end content block #MSG: $smtp->datasend("--*BCKTR*\n"); $smtp->datasend("Content-Type: ".$MIMEtype{html}[0]."; charset +=UTF-8\n"); $smtp->datasend("\n"); #end content block $smtp->datasend("$email_msg"); $smtp->datasend("\n"); #ATTACHMENTS my $path = "$reportconfig{sharedriveletter}:\\$system->{serial +}->[0]\\"; for (my $f = 1; $f < @{$system->{filename}}; $f++) { if (-e "$path$system->{filename}->[$f]") { logLine("attaching file $system->{filename}->[$f]"); $smtp->datasend("--*BCKTR*\n"); $smtp->datasend("Content-Type: ". $MIMEtype{substr($sy +stem->{filename}->[$f],index($system->{filename}->[$f],".") + 1)}[0] +."; name=\"$system->{filename}->[$f]\"\n");#; charset=binary $smtp->datasend("Content-Transfer-Encoding: ". $MIMEty +pe{substr($system->{filename}->[$f],index($system->{filename}->[$f]," +.") + 1)}[1] ."\n"); $smtp->datasend("Content-Disposition: attachment; file +name=\"$system->{filename}->[$f]\"\n"); $smtp->datasend("\n"); #end content block open (ATT, "< $path$system->{filename}->[$f]"); while (my $input = <ATT>) { if ($MIMEtype{substr($system->{filename}->[$f],ind +ex($system->{filename}->[$f],".") + 1)}[1] eq "base64") { $input = encode_base64($input); } $smtp->datasend($input); } close (ATT); $smtp->datasend("\n"); #separate each file with a new +line } } if ($system->{status}->[0] =~ m/fail/i) { $files{log}{file} =~ m/([a-zA-Z0-9\-\._]+)$/; my $logfile = $1; $smtp->datasend("--*BCKTR*\n"); $smtp->datasend("Content-Type: ".$MIMEtype{log}[0]."; name +=\"$logfile\"\n"); $smtp->datasend("Content-Transfer-Encoding: ". $MIMEtype{l +og}[1] ."\n"); $smtp->datasend("Content-Disposition: attachment; filename +=\"$logfile\"\n"); $smtp->datasend("\n"); #end content block open (ATT, "< $files{log}{file}"); while (my $input = <ATT>) { $smtp->datasend($input); } close (ATT); $smtp->datasend("\n"); #separate each file with a new line } # Send the END section break $smtp->datasend("--*BCKTR*--\n\n"); #end data to server $smtp->dataend(); #close connection to server (SEND) $smtp->quit; }

In reply to SMTP send time by glenn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.