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
Hi,

I actually do mine different in my own code. This sends out a 2 part message (plain text and HTML). Its important these days to send out both plain and HTML versions, as it will help you with spam filters.

Code:
sub do_emailing_new {
# Plugins::Emails::do_emailing_new("foo_bar_template","Some subject",$opts)

use MIME::Lite;
use MIME::Base64;
use Encode;
use Links::SiteHTML;

my ($template,$subject,$opts) = @_;

my $to = $opts->{to};

my $from = $opts->{from} || '"Andy" <andy@mysite.com>';

my $html = Links::SiteHTML::display($template, { %$opts } );
my $text = Links::SiteHTML::display("${template}_txt", { %$opts }, { compress => 0 } );

$html = decode( 'utf-8', $html );
$text = decode( 'utf-8', $text );

# print "FOO: $html \n";

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

# multipart message
my @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",
}
)
);

if ($opts->{attach_file}) {

my $filename = (reverse split /\//, $opts->{attach_file})[0];

push @parts, Email::MIME->create(
attributes => {
filename => $filename,
content_type => "application/pdf",
encoding => "base64",
name => $filename,
},
body => io( $opts->{attach_file} )->binary->all,
)
}


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

#print $email->as_string. "\n\n";

my $bcc = '';
my $bcc = 'andy@ultranerds.co.uk';
if ($bcc) {
sendmail($email,{ to => [$to, $bcc] });
} else {
sendmail($email->as_string);
}

}

Basically you create 2 templates - template_name.html and template_name_txt.html

Call with:

Code:
Plugins::Emails::do_emailing_new("foo_bar_template","Some subject",$opts)
;

$opts contains the following variables:

Code:
from
to (email)

From memory, both of those can be in the format is:

Code:
Some persons name <andy.newby@gmail.com>

I'm sure you can figure out the rest :)

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 11185 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 7255 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 7238 Mar 20, 2020, 4:34 AM
Post Re: [delicia] Sending file by email blues :(
Andy 7248 Mar 20, 2020, 2:01 AM