#!/usr/bin/perl
use warnings;
use strict;
use Net::SMTP::SSL;
+
use MIME::Lite;
# Implements the same API as Net::SMTP, but uses IO::Socket::SSL for i
+ts
# network operations. Due to the nature of "Net::SMTP"'s "new" method,
+ it
# is not overridden to make use of a default port for the SMTPS servic
+e.
# Perhaps future versions will be smart like that. Port 465 is usually
+
# what you want, and it's not a pain to specify that.
# GMAIL's virus scanners have trouble with .zip and .exe attachments??
# and the smtp server rejects mails with those attachments
#$server = 'your-smtp-server';
my $server = 'smtp.gmail.com';
my $to = 'who@freak.com';
my $from_name = 'me';
my $from_email = 'me@gmail.com';
my $subject = 'smtp-ssl-auth attach test';
my $user = 'me@gmail.com';
my $pass = 'my_password';
my $msg = MIME::Lite->new(
From => $from_email,
To => $to,
Subject =>'test message',
Type =>'TEXT',
Data =>'This is a test, i repeat only a test',
);
#$msg->attach(Type =>'application/octet-stream',
#Encoding =>'base64',
#Path =>'./zenbw_l.jpg',
#);
$msg->attach(
Type => 'application/vnd.ms-excel',
Path => './zz.xls',
Filename => 'college_orders.xls',
Encoding => 'base64'
);
my $smtps = Net::SMTP::SSL->new($server,
Port => 465,
DEBUG => 1,
) or warn "$!\n";
# I hust lucked out and this worked
defined ($smtps->auth($user, $pass))
or die "Can't authenticate: $!\n";
$smtps->mail($from_email);
$smtps->to($to);
$smtps->data();
$smtps->datasend( $msg->as_string() );
$smtps->dataend();
$smtps->quit();
print "done\n";
#You can alternatively just put everything in the argument to $smtp->d
+ata(),
#and forget about datasend() and dataend();
|