| Category: | E-Mail Programs |
| Author/Contact Info | Shobhan Challa |
| Description: | This code demonstrates how to use MIME::Entity and MIME::Types to add attachment(s) to an outgoing email. |
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Entity;
use Net::SMTP;
use MIME::Types;
my $mimetypes = MIME::Types->new;
my $from = 'bt-user@localhost';
my $to = 'bt-user@localhost';
# Get File details
my $file2attach = "/tmp/data.html";
#Create MIME entity
my $mime = MIME::Entity->build(
From => $from,
To => $to,
Subject => "This is a subject",
Data => " This is the mail body :)",
);
$mime->attach(
Path => $file2attach,
Type => ($mimetypes->mimeTypeOf($file2attach) || "application/octe
+t-stream"),
Encoding => '-SUGGEST',
);
# SEND Mail
my $smtp = Net::SMTP->new('localhost');
$smtp->mail($from);
$smtp->to($to);
$smtp->data();
$smtp->datasend($mime->stringify);
$smtp->dataend();
$smtp->quit;
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Send email with attachment(s)
by chanio (Priest) on Jan 18, 2005 at 20:26 UTC | |
|
Re: Send email with attachment(s)
by Anonymous Monk on Sep 06, 2007 at 14:38 UTC |