sendmail attachment
am 03.01.2009 00:54:40 von Mario Sanchez
--===============1050759525==
Content-Type: multipart/alternative;
boundary="----=_Part_135348_28994029.1230940480314"
------=_Part_135348_28994029.1230940480314
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
dear perl gurus
i *have* to use a hosting service that does not have/allow Mime::Lite so i
am pretty much stuck with the classic sendmail. but i need to send
attachments. the hosting service is godaddy - i mention them not to
denigrate but in case someone else found a solution with this hosting
service.
my code
sub emailnotice{
$mailprog = '/usr/lib/sendmail';
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: '$email'\n";
print MAIL "To: '$email'\n";
print MAIL "From: '$email'\n";
print MAIL "Subject: Customer Submitted Info -Web Site\n\n";
print MAIL $thetext;
close (MAIL);
}
works great. the $thetext is presently a text file that i read in and simply
put it in the body - quickly becoming impractical .... also tried the *uuencode
*- perhaps did not that do right ...
though i tried in vain, how can i attach either a binary file or a text file
using sendmail?
thank you in advance ...
mario
------=_Part_135348_28994029.1230940480314
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
dear perl gurus
i *have* to use a hosting service that does not have/allow Mime::Lite so i am pretty much stuck with the classic sendmail. but i need to send attachments. the hosting service is godaddy - i mention them not to denigrate but in case someone else found a solution with this hosting service.
my code
sub emailnotice{
$mailprog = '/usr/lib/sendmail';
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Reply-to: '$email'\n";
print MAIL "To: '$email'\n";
print MAIL "From: '$email'\n";
print MAIL "Subject: Customer Submitted Info -Web Site\n\n";
print MAIL $thetext;
close (MAIL);
}
works great. the $thetext is presently a text file that i read in and simply put it in the body - quickly becoming impractical .... also tried the uuencode - perhaps did not that do right ...
though i tried in vain, how can i attach either a binary file or a text file using sendmail?
thank you in advance ...
mario
------=_Part_135348_28994029.1230940480314--
--===============1050759525==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1050759525==--
Re: sendmail attachment
am 03.01.2009 01:06:02 von Jenda Krynicky
From: "Dr. Mario Sanchez"
> i *have* to use a hosting service that does not have/allow Mime::Lite so i
> am pretty much stuck with the classic sendmail. but i need to send
> attachments. the hosting service is godaddy - i mention them not to
> denigrate but in case someone else found a solution with this hosting
> service.
If you can upload your code, you can upload MIME::Lite or
Mail::Sender. Not sure about MIME::Lite, but Mail::Sender is plain
Perl and a single file and the only noncore dependencies are
MIME::Base64 and MIME::QuotedPrint.
Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: sendmail attachment
am 03.01.2009 01:35:24 von Bill Luebkert
Dr. Mario Sanchez wrote:
> dear perl gurus
>
> i *have* to use a hosting service that does not have/allow Mime::Lite so
> i am pretty much stuck with the classic sendmail. but i need to send
> attachments. the hosting service is godaddy - i mention them not to
> denigrate but in case someone else found a solution with this hosting
> service.
> though i tried in vain, how can i attach either a binary file or a text
> file using sendmail?
If they allow Net::SMTP you can do something like:
# Net::SMTP: send attachment using Net::SMTP
use strict;
use warnings;
use Net::SMTP;
use MIME::Base64; # email if you need a substitute base64
my $file = $ARGV[0] || 'some.gif'; # file to attach
my $ct = 'image/gif'; # content type for attachment
my $smtphost = '192.168.4.106'; # SMTP mail host
my $from = 'kbarker@americallgroup.com';
my $to = 'kbarker@americallgroup.com';
# get the GIF
my $content;
{ local $/ = undef; # slurp file
open IN, $file or die "Error opening $file: $!";
binmode IN;
$content = ;
close IN;
}
# skip encode if using text
my $encode = encode_base64 ($content); # base 64 encode it
my $boundary = '<------------ FUBAR: ';
my @chrs = ('0' .. '9', 'A' .. 'Z', 'a' .. 'z');
foreach (0..16) { $boundary .= $chrs[rand (scalar @chrs)]; }
$boundary .= ' ------------>';
my $msg = <
From: $from
To: $to
Reply-To: $from
Subject: Test image attach to Net::SMTP
MIME-Version: 1.0
X-Mailer: fubar.pl
Content-Type: multipart/mixed; boundary="$boundary"
This is a multipart MIME-coded message
--$boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Attached is a GIF file.
--$boundary
Content-Type: $ct; name="$file"
Content-Disposition: inline; filename="$file"
Content-Transfer-Encoding: base64
$encode
--$boundary--
EOD
my $smtp = Net::SMTP->new($smtphost, Debug => 1) or die "Net::SMTP::new: $!";
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend($msg);
$smtp->dataend();
exit;
__END__
Without Net::SMTP, something like this might do ya:
open MAIL, "|/usr/lib/sendmail -t";
print MAIL <
To: $destination
From: $sender
Subject: Consultant Hours Worked Submission
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="<-----Some Garbage [$$] --------->"
--<-----Some Garbage --------->
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Attached is an .rtf file from work. (or whatever)
--<-----Some Garbage --------->
Content-Type: application/rtf; name="$txtfile"
Content-Transfer-Encoding: base64
$encode
--<-----Some Garbage --------->--
EOD
close MAIL;
}
__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: sendmail attachment
am 05.01.2009 18:12:23 von Andy_Bach
You can build your own sendmail msg and MIME sections, depending on the
attachment content. If it's a binary (jpg, exe etc) you'll have to find a
way to Base64 (or some such) encode it but otherwise, you can just build up
a msg and header and open up a sendmail -t and write your header and msg
etc.
a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
Voice: (608) 261-5738; Cell: (608) 658-1890
Straw? No, too stupid a fad. I put soot on warts.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs