#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    How add Message-ID


    I have zero experience with Perl and hope someone can help me. I purchased a Perl script a couple of years ago and it seams development and support for it are dead.

    I want to add a compliant Message-ID header to the emails the script sends.

    Below are the relevant snippets of code:

    Code:
    sub SendMail
    {
    my ($mail_to, $mail_from, $subject, $body) = @_;
    
    open (OUTMAIL,"|".$c->{sendmail_path} ." -t") || return;
    $subject = '=?UTF-8?B?'.encode_base64($subject);
    chomp($subject);
    $subject.='?=';
    print OUTMAIL <<EOM;
    To:   $mail_to
    From: $mail_from
    Subject: $subject
    Content-Type: text/html; charset=UTF-8
    
    
    $body
    .
    EOM
    ;
    close OUTMAIL;
    }
    
    sub SendMail1
    {
    my ($mail_to, $mail_from, $subject, $body) = @_;  
    open (OUTMAIL,"|".$c->{sendmail_path} ." -t") || return "Can't open Unix Sendmail:".$!;
    print OUTMAIL <<EOM;
    To:   $mail_to
    From: $mail_from
    Subject: $subject
    Content-Type: text/html; charset=utf-8
    
    
    $body
    .
    EOM
    ;
    close OUTMAIL;
    }

    Code:
    ### Send E-mail to Admin
    if($c->{confirm_email})
    {
       my @t = &getTime;
       my $tmpl = HTML::Template->new( filename => "Templates/confirm_email.html", die_on_bad_params => 0 );
       $tmpl->param('files'     => \@files,
                    'params'    => \@har,
                    'time'      => "$t[0]-$t[1]-$t[2] $t[3]:$t[4]:$t[5]",
                    'total_size'=> "$ENV{CONTENT_LENGTH} bytes",
                    'total_size_mb' => sprintf("%.1f",$ENV{CONTENT_LENGTH}/1048576)." Mb",
                   );
       my $subject = $c->{email_subject} || "XUpload: New file(s) uploaded";
       &SendMail( $c->{confirm_email}, $c->{confirm_email_from}, $subject, $tmpl->output() );
    
       #require MIME::Lite;
       #my $msg = MIME::Lite->new ( 
       #  From => $c->{confirm_email_from}, 
       #  To => $c->{confirm_email}, 
       #  Subject => $subject, 
       #  Type =>'multipart/mixed' 
       #) or die "Error creating multipart container: $!\n"; 
       #$msg->attr("content-type.charset" => "UTF-8");
       
       #$msg->attach(Type => 'text/html', Data => $tmpl->output ); 
       
       #for(@files)
       #{
       #   $msg->attach ( 
       #      Type => 'application/octet-stream', 
       #      Path => "$c->{target_dir}/$_->{file_name}", 
       #      Filename => $_->{file_name}, 
       #      Disposition => 'attachment' 
       #   ) if $c->{email_file_attach};
       #}
       #$msg->send;
    }
    
    ### Send E-mail to Uploader
    if($cg->param('email_notification'))
    {
       &lmsg("MSG: ".$c->{msg}->{send_email_note});
       my @t = &getTime;
       my $tmpl = HTML::Template->new( filename => "Templates/confirm_email_user.html", die_on_bad_params => 0 );
       $tmpl->param('files'        => \@files,
                    'time'          => "$t[0]-$t[1]-$t[2] $t[3]:$t[4]:$t[5]",
                    'total_size'    => "$ENV{CONTENT_LENGTH} bytes",
                    'total_size_mb' => sprintf("%.1f",$ENV{CONTENT_LENGTH}/1048576)." Mb",
                   );
       my $subject = $c->{email_subject} || "XUpload: File upload confirmation";
       &SendMail( $cg->param('email_notification'), $c->{confirm_email_from}, $subject, $tmpl->output );
    }
    I googled for hours and never found an example that I could get to work.

    Can someone please provide an example and where in the current code it should be added?

    Cheers,

    Jeff
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,782
    Rep Power
    4301
    Do you know how to generate a message_id header value. If so, just add the one line to add a Message-Id header right below the Content-Type within the two sections of code.

    However, what you're using is a really old and ugly script. It would be much better to use a built in perl module, such as Mail::Sender or Mail::SendMail.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo