Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

GT::Mail module help needed

Quote Reply
GT::Mail module help needed
I have a mail content (header+body together) in a variable.

How can I pass this to GT::Mail module?
I would like to parse it from this variable into parts, encode as needed, add new header items,
then create the mail & send it through sendmail.
I do not see if GT::Mail::Parse can do this...

Is there a way to do that?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] GT::Mail module help needed In reply to
The first part of the task is solved, but I still have problems.

Let me show what is solved now:
Code:
use strict;
use warnings;

use Data::Dumper;
use GT::Mail::Parse;

my $mail_txt = q|To: <info@mydomain.hu>
From: <info@mydomain.hu>
Errors-To: <info@mydomain.hu>
Subject: Test email subject

test email message body
|;

my $parser = new GT::Mail::Parse;
my $top = $parser->parse (
in_string => $mail_txt,
debug => 1
) or die $GT::Mail::Parse::error;
print '$top: ' . Dumper(\$top) . "";
Note, the 'in_string' option was missing from the GT::Mail::Parse documentation!

This parses the whole mail text from $mail_txt variable into parts stored in $top object.


This is ok, now, but
1) how to send this GT::Mail::Parse object away, likely with the GT::Mail::send method?
2) how to flatten this object back to a SCALAR variable to display it?

Any suggestions?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] GT::Mail module help needed In reply to
Ah, got it.

It seems, the GT::Mail::parse method can also accept SCALAR, which is not mentioned in the GT::Mail documentation!


Fortunately there was a comment in the code:
Quote:
# $obj->parse(\*FH);
# ------------------
# $obj->parse('/path/to/file');
# -----------------------------
# $obj->parse($SCALAR_REF -or- $SCALAR);
# --------------------------------------
# Takes either a path to a file for a file handle. Returns 1 on success and
# undef on failure. If a filehandle is specified this will attempt to seek back
# to 0, 0 on exit.


Here is the successful code:
Code:
use strict;
use warnings;

use Data::Dumper;
use GT::Mail;


# Get a new mailer object
my $mailer = new GT::Mail();

# Input a text email string, with full header
my $mail_txt = q|To: Hisname <info@hisdomain.com>
From: Myname <me@mydomain.com>
Errors-To: Hisname <info@hisdomain.com>
Subject: Test email subject

test email message body
|;

# Parse the string
$mailer->parse($mail_txt);

#Flatten mail object into string
my $mail_result = $mailer->as_string();
print '$mail_result: ' . Dumper(\$mail_result) . "";

#Send the email
$mailer->send(smtp => 'mail.mydomain.com') || die "Error sending message\n";

print "Mail sent successfully!\n";

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Dec 25, 2005, 2:15 PM