Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How do I send text / html Mail with GT::Mail

Quote Reply
How do I send text / html Mail with GT::Mail
Hi,

I am trying to find out how to do the above.
I found:
Code:
use MIME::Lite;

my $from = 'I Programmer <sender@sender.com>';
my $subject = 'I am a Perl programmer';
my $to = 'rec@rec.com';
my $html = q|
<a href="http://www.link.info/">
I-Programmer
</a>
|;

my $text = q|
We can only have text links here
http://www.link.info/
|;

my $msg = MIME::Lite->new(
From => $from,
To => $to,
Type => 'multipart/alternative',
Subject => $subject,
);

my $att_text = MIME::Lite->new(
Type => 'text',
Data => $text,
Encoding => 'quoted-printable',
);
$att_text->attr('content-type'
=> 'text/plain; charset=UTF-8');
$msg->attach($att_text);

my $att_html = MIME::Lite->new(
Type => 'text',
Data => $html,
Encoding => 'quoted-printable',
);
$att_html->attr('content-type'
=> 'text/html; charset=UTF-8');
$msg->attach($att_html);

$msg->send;
And thought I could do something like:
Code:
my $html_mail = Links::send_email('mail_html.eml',$results, { get_body => 1 });
my $txt_mail = Links::send_email('mail_txt.eml',$results, { get_body => 1 });
use GT::Mail;
my $send = new GT::Mail (
type => 'multipart/alternative',
to => 'rec@rec.com',
from => 'sender@sender.com',
subject => "subject",
msg => '',
debug => 0,
sendmail => $CFG->{db_mail_path},
);
$send->attach(
type => 'text/plain; charset=UTF-8',
body_data => $txt_mail
);
$send->attach(
type => 'text/html; charset=UTF-8',
body_data => $html_mail
);
$send->send() or die "Error: $GT::Mail::error";
But I think I am a little off track here.

Thanks for any help

n||i||k||o
Quote Reply
Re: [el noe] How do I send text / html Mail with GT::Mail In reply to
This is how I do it:

Code:
my $html = Links::SiteHTML::display("leads_contactpaid", { %$link, %$user } );
my $text = Links::SiteHTML::display("leads_contactpaid_txt", { %$link, %$user } );

my $msg = MIME::Lite->new(
From => $from,
To => $to,
Type => 'multipart/alternative',
Subject => $subject,
);

my $att_text = MIME::Lite->new(
Type => 'text',
Data => $text,
Encoding => 'quoted-printable',
);

$att_text->attr('content-type' => 'text/plain; charset=UTF-8');
$msg->attach($att_text);

my $att_html = MIME::Lite->new(
Type => 'text',
Data => $html,
Encoding => 'quoted-printable',
);
$att_html->attr('content-type' => 'text/html; charset=UTF-8');
$msg->attach($att_html);

$msg->send;

Not super pretty - but it does the job :)

Cheers

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!
Quote Reply
Re: [Andy] How do I send text / html Mail with GT::Mail In reply to
Hi Andy,

Thanks for sharing that piece of code and I am happy that you are still around, was a little afraid when I saw your new website.
Looks nice, if you did not get a comment from me there might be a problem with the contact form and chrome. The loader did not disappear.

Cheers

n||i||k||o
Quote Reply
Re: [el noe] How do I send text / html Mail with GT::Mail In reply to
Hi,

Yup - I'm still around :)

Thanks for the heads up about the contact page. I didn't realise that was broken. I'll take a look into it.

Cheers

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!