Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending an Attachment through Lotus Notes using Perl

Status
Not open for further replies.

kiperez

Programmer
Feb 9, 2005
11
US
I need to send an attachment programatically using Perl...

I tried MIME Base64 but the file isn't really an attachment -- it's part of the message body.

how do I do this?
 
I'm using SMTP on a Lotus Notes network and for some reason when I use MIME::Lite, the address of the person I'm sending it to doesn't get resolved. If I use NET::SMTP or MIME::Entity or MIME::Base64 I get the message but there is no attachment.
If I use those last lines that are commented out is when I get the file as part of the message.

Any help here would be great. Thanks!

sample code follows...
sub FileAttach {
$msg = new MIME::Lite;
$msg->build( From => "ESM@orbitz.com",
To => "kperez@orbitz.com",
Subject => "Your XLS File",
Type => "AUTO",
Path => $FName,
ReadNow => 1);

MIME::Lite->send("smtp", "mailhost.noc.duncllc.com", Timeout=>60);
$msg->send; ### will now use Net::SMTP as shown above
# $msg->send_by_smtp("mailhost.noc.duncllc.com");
}

sub SendXLSFile
{
print "Emailing ", $FName, "\n";
$smtp = Net::SMTP->new( "mailhost.noc.duncllc.com");

$smtp->mail("ESM@orbitz.com");
$smtp->to('kperez@orbitz.com');

$smtp->data();
$smtp->datasend("To: kperez@orbitz.com\n");
$smtp->datasend("Subject: ResponseTimes ready\n");
$smtp->datasend("From: ESM\@orbitz.com\n");
# $self->datasend("MIME-Version: 1.0\n");
# $self->datasend(sprintf "Content-Type: multipart/mixed; BOUNDARY=\"%s\"\n",$b);

$smtp->datasend("\n");
$smtp->datasend($FName . "\n is ready\n");
$file = $FName;
FileAttach;
$smtp->dataend();
$smtp->quit;


# $smtp1 = Net::SMTP::Multipart->new("mailhost.noc.duncllc.com");
# $smtp1->Header( "kperez@orbitz.com", "Multipart Mail Demo", "ESM@orbitz.com");
# $smtp1->Text( "This is the first text part of the message");
# $smtp1->FileAttach( $FName");
# $smtp1->End();
}


 
Code:
#usr/bin/perl
use MIME::Entity;
use Crypt::Blowfish;

    $mailprog = '/usr/sbin/sendmail';$auto_type = 'text/plain';$auto_encoding = 'base64';
    $auto_body = 'body.txt';$message_type = 'multipart/mixed'; $log_or_email = 'B';
    $email_log = 'automail_lite.log';

    $RealFile = "P$hour$min$sec$year$yday-$pid.pck";
    open (TXT, ">$RealFile");
    $msg_body = "whatever you want to send in a text file";
    my $tmp = $msg_body;
    ($msg_body = $tmp) =~ s/\n/$1/;

    $key = pack("H*", "ABCFDE1090FFFFFF");
    $cipher = new Crypt::Blowfish $key;
    $ipos = 0;
    while ($ipos < length $msg_body) {
        $this_chunk = substr($msg_body, $ipos, 8);
        $ipos = $ipos + 8;
        if (length $this_chunk < 8) {
            for ($i = length $this_chunk; $i < 8; $i++) {
                $this_chunk = $this_chunk." ";
                 }   
        }
        $ciphertext = $cipher->encrypt("$this_chunk");  # NB - 8 bytes
        print TXT "$ciphertext";
    }
    close (TXT);
    
    $Body = "new mail from webserver\n\n";    
    &send_mail;
    
    @file = "$RealFile";
    unlink @file;
    $Body = "Thank you for doing business with us\n";



sub send_mail {
local($print_config,$key,$sort_order,$sorted_field,$env_report); 
$top = build MIME::Entity Type => "multipart/mixed",
                          From => "webserver\@yourdomain.com",
                          To => "whoever\@yourdomain.com",
                          Subject => "New $title request from webserver"; 
attach $top Data=> $Body;
attach $top Path => "$RealFile",Type => "text/plain" ,Encoding => "base64"; 
open MAIL, "|$mailprog -t -i" or die "open: $!";
$top->print(\*MAIL);
close MAIL; 
}

This code (or something that resembles it closely) has worked for me in the past

HTH
--Paul

There's no possibility that your AV, or mail agent is stripping the attachement as a potential threat ?

cigless ...
 
I tried using MIME::Entity before and I couldn't get it to send the message. I keep getting "Connection not established".

Attaching File: N:/Mercury-Topaz/HotelSearch-Reports/Response Times - Friday 02-
11-2005.xls
Failed to send the message: Connection not established

in your send_mail subroutine...
I don't use sendmail. has to be SMTP

but I get it when I do it like this...
sub SendXLSFile
{
print "Emailing ", $FName, "\n";
$smtp = Net::SMTP->new( "mailhost.noc.duncllc.com");

$smtp->mail("ESM@orbitz.com");
$smtp->to('kperez@orbitz.com');

$smtp->data();
$smtp->datasend("To: kperez@orbitz.com\n");
$smtp->datasend("Subject: ResponseTimes ready\n");
$smtp->datasend("From: ESM\@orbitz.com\n");
$self->datasend("MIME-Version: 1.0\n");
$self->datasend(sprintf "Content-Type: multipart/mixed; BOUNDARY=\"%s\"\n",$b);

$smtp->datasend("\n");
$smtp->datasend($FName . "\n is ready\n");
$file = $FName;
FileAttach;
$smtp->dataend();
$smtp->quit;


$smtp1 = Net::SMTP::Multipart->new("mailhost.noc.duncllc.com");
$smtp1->Header( "kperez@orbitz.com", "Multipart Mail Demo", "ESM@orbitz.com");
$smtp1->Text( "This is the first text part of the message");
$smtp1->FileAttach( $FName");
$smtp1->End();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top