Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I've had many problems with mail clients marking email as potential spam due to changes in the RFC related to the date and time stamp functions. Moy code has to work on Win32 and Linux boxes, too, and sendmail doesn't. So I wrote the following sub that uses NET::SMTP. It auto detects the missing SASL and Base64 pods on Activestate Win32 machines so it can authenticate to remote servers.
sub SMTPMail { use Net::SMTP; # Not all versions of SMTO support authentication. my ($to, $from, $subj, $msg, $smtpserver) = @_; my $body = ""; my $error; eval { require MIME::Base64; require Authen::SASL; }; if ($@) { $error = system("ppm install MIME::Base64"); $error = system("ppm install Authen::SASL"); } ; my @dayofweek = (qw(Sun Mon Tue Wed Thur Fri Sat)); my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov De +c)); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(); $year += 1900; #Create an RFC compliant time stamp my $Date = sprintf("%s, %02d %3s %04d %02d:%02d:%02d CST",$dayofwee +k[$wday],$mday,$monthnames[$mon],$year,$hour,$min,$sec); # Make $to into an array if it's not one already if (!ref($to)) { @$to = split(/[,;]\s*/, $to); } # Make Email Header $body = "MIME-Version: 1.0\n" . "From: $from\n" . "To: " . join(',', @$to) . "\n" . "Date: ".$Date."\n" . "Subject: $subj\n\n" # Double \n . $msg . "\n"; my $smtp; # Open a SMTP session if(!($smtp = Net::SMTP->new($smtpserver))) { return "Could not connect to SMTP Server: $smtpserver "; } if (length($EmailAuth) > 0 && length($EmailPassword) > 0 ) { &LogFile("Email","Auth $EmailAuth"); my $error = $smtp->auth($EmailAuth,$EmailPassword) ; if (! $error) { return "Cannot authenticate as user $EmailAuth and/or b +ad Password for Email - Error $error - Check System Settings "; } } # Pass the 'from' email address, exit if error if (! ($smtp->mail( $from ) ) ) { return "Bad 'From', check your Ac +count Information"; } # Pass the recipient address(es) if (!($smtp->recipient(@$to))) { return "Bad 'EmailTo'"; } # Send the msg $smtp->data( $body ); $smtp->quit; return 0; }

In reply to Answer: How do I send e-mail from my Perl Program? by QandAEditors

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (8)
    As of 2018-06-22 15:47 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (124 votes). Check out past polls.