Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Send email with attachment(s)

by chanakya (Friar)
on Jan 18, 2005 at 09:49 UTC ( [id://422956]=sourcecode: print w/replies, xml ) Need Help??
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
    Hey Very very Thanks. The code helped me lot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://422956]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found