#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use warnings;
use Net::SMTP;
use MIME::Base64;
my ($buf, $picture);
my $company = 'my_company.com';
my $path = "/home/sites/$company/public_html";
my $attachBinaryFile = "image.jpg";
my $boundary = 'frontier';
my $passwd = "password";
my $contact = "name";
my $email = "somebody\@somewhere.com";
$smtp = Net::SMTP->new("mail.$company", Timeout => 30,Debug => 0,);
$smtp->datasend("AUTH LOGIN\n");
$smtp->response();
$smtp->datasend(encode_base64("$contact\@$company") );
$smtp->response();
$smtp->datasend(encode_base64("$passwd") );
$smtp->response();
$smtp->mail("$contact\@$company");
$smtp->to($email);
$smtp->cc();
$smtp->data();
$smtp->datasend("To: $email\n");
$smtp->datasend("From: $contact\@$company\n");
$smtp->datasend("Subject: Try-out of email script\n");
#$smtp->datasend("Cc: info\@$company\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundary\"\n");
#$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
#$smtp->datasend("Content-type: text/plain; charset=\"UTF-8\"\n");
$smtp->datasend("Content-type: text/plain;\n");
$smtp->datasend("\nSome plain text here in the body of the email\n");
$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
$smtp->datasend("Content-Type: image/jpeg; name=\"$attachBinaryFile\"\n");
$smtp->datasend("Content-Transfer-Encoding: base64\n");
$smtp->datasend("Content-Disposition: attachment; filename=\"$attachBinaryFile\"\n");
$smtp->datasend("\n");
open(DAT, "$path/$attachBinaryFile") || die("Could not open binary file!");
binmode(DAT);
local $/=undef;
while (read(DAT, $picture, 4096)) {
$buf = &encode_base64( $picture );
$smtp->datasend($buf);
}
close(DAT);
$smtp->datasend("\n");
$smtp->datasend("--$boundary\n");
$smtp->dataend();
$smtp->quit;
print "Mail sent\n";
exit;
print "