Gossamer Forum
Home : General : Perl Programming :

Re: [delicia] Sending file by email blues :(

Quote Reply
Re: [delicia] Sending file by email blues :( In reply to
Man that was a pain - but got there in the end! This is a working function I now have:

Code:

use Email::MIME;
use Email::Address::XS;
use Email::Sender::Simple qw(sendmail);
use IO::All;
use GT::MIMETypes;

my $to = 'support@foo.co.uk'; #$rec{'Email'};

my $from = $admin_email;
my $subject = "some title";
my $html = "some test <b>message</b> foo bar test";
my $text = "some test message some plain version";
$html = decode( 'utf-8', $html );
$text = decode( 'utf-8', $text );

# multipart message
my @message_parts = (
Email::MIME->create(
body_str => $text,
attributes => {
encoding => 'quoted-printable',
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
}
),
Email::MIME->create(
body_str => $html,
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/html",
disposition => "inline",
}
)
);


my @all_parts;
push @all_parts, Email::MIME->create(
parts => \@message_parts, # add all the message parts into here...
attributes => {
content_type => "multipart/alternative"
}
);

my $attach = "/home/user/web/foo.co.uk/public_html/cgi-bin/admin/tables.cgi";

if ($attach) {

my $filename = (reverse split /\//, $attach)[0]; # also changed in body => below

# better to use GT::MIMETypes if you have it with Fileman (pretty sure you do?)
my $mime = GT::MIMETypes::guess_type($filename);

push @all_parts, Email::MIME->create(
attributes => {
filename => $filename,
content_type => $mime,
encoding => "base64",
name => $filename
},
body => io( $attach )->binary->all,
)
}


my $email = Email::MIME->create(
header_str => [
From => $from,
To => [ $to ],
Subject => $subject
],
parts => \@all_parts,
attributes => {
encoding => 'base64',
content_type => "multipart/mixed"
}
);

print qq|Structure: | . $email->debug_structure. "\n\n";


sendmail($email->as_string);

The important part is that you create one set of "parts" for the plain and html text. Then another for the attachments.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread Sending file by email blues :( Andy 13304 Aug 27, 2001, 4:22 AM
Thread Re: Sending file by email blues :(
Paul 13111 Aug 27, 2001, 4:35 AM
Thread Re: Sending file by email blues :(
Andy 13135 Aug 27, 2001, 5:30 AM
Post Re: Sending file by email blues :(
Paul 13095 Aug 27, 2001, 5:35 AM
Thread Re: Sending file by email blues :(
Paul 13117 Aug 27, 2001, 5:36 AM
Post Re: Sending file by email blues :(
Andy 13106 Aug 27, 2001, 5:40 AM
Thread Re: Sending file by email blues :(
Alex 13093 Aug 27, 2001, 9:54 AM
Post Re: Sending file by email blues :(
Andy 13078 Aug 27, 2001, 12:35 PM
Thread Re: [Andy] Sending file by email blues :(
delicia 11204 Feb 3, 2020, 8:01 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 11200 Feb 3, 2020, 10:21 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 11198 Feb 3, 2020, 11:44 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 11186 Feb 4, 2020, 12:09 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 11180 Feb 4, 2020, 6:51 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 11183 Feb 4, 2020, 6:53 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10708 Mar 15, 2020, 7:36 AM
Post Re: [delicia] Sending file by email blues :(
Andy 10701 Mar 16, 2020, 12:16 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10701 Mar 16, 2020, 12:18 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10689 Mar 16, 2020, 1:32 PM
Thread Re: [delicia] Sending file by email blues :(
Andy 10683 Mar 17, 2020, 12:14 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10620 Mar 18, 2020, 4:54 PM
Thread Re: [delicia] Sending file by email blues :(
Andy 10613 Mar 18, 2020, 11:49 PM
Thread Re: [Andy] Sending file by email blues :(
delicia 10610 Mar 19, 2020, 2:40 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10603 Mar 19, 2020, 4:03 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 10600 Mar 19, 2020, 5:29 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 10593 Mar 19, 2020, 5:32 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7279 Mar 19, 2020, 5:38 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7277 Mar 19, 2020, 5:46 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7277 Mar 19, 2020, 5:53 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7276 Mar 19, 2020, 5:57 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7278 Mar 19, 2020, 6:04 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7273 Mar 19, 2020, 6:08 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7271 Mar 19, 2020, 6:20 AM
Thread Re: [delicia] Sending file by email blues :(
delicia 7266 Mar 19, 2020, 8:24 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7268 Mar 19, 2020, 8:45 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7264 Mar 19, 2020, 10:21 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7256 Mar 20, 2020, 12:06 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7246 Mar 20, 2020, 3:23 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7247 Mar 20, 2020, 3:38 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7251 Mar 20, 2020, 3:43 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7244 Mar 20, 2020, 3:45 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7242 Mar 20, 2020, 3:50 AM
Thread Re: [delicia] Sending file by email blues :(
Andy 7242 Mar 20, 2020, 4:10 AM
Thread Re: [Andy] Sending file by email blues :(
delicia 7248 Mar 20, 2020, 4:29 AM
Post Re: [delicia] Sending file by email blues :(
Andy 7239 Mar 20, 2020, 4:34 AM
Post Re: [delicia] Sending file by email blues :(
Andy 7249 Mar 20, 2020, 2:01 AM