Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Email::Mime not able to send array in mesg body

19 views
Skip to first unread message

Rajeev Prasad

unread,
Feb 20, 2013, 1:41:51 PM2/20/13
to perl list
hello follwoing code is sending empty email body. I am trying to send HTML content in body of mesg. It works if I use a string instead of array. I tried sending reference to @email_body, but It simply printed array_ref in body.

modules used are:

use Email::MIME;
use Email::Sender::Simple qw(sendmail);


open(my $tmp_fh,"<",html_file) or die "error: $!";
    @email_body = <$tmp_fh>;
close $tmp_fh;

    my $message = Email::MIME->create(
      header_str => [
        From    => '<jo...@apple.com>',
        To      => '<jac...@banana.com>',
        Subject => "Please see my test email",
      ],
      attributes => {
        encoding => 'quoted-printable',
        charset  => 'ISO-8859-1',
        content_type => 'text/html'
      },
      body_str => @email_body,
    );

    sendmail($message);

David Precious

unread,
Feb 20, 2013, 2:01:50 PM2/20/13
to begi...@perl.org
On Wed, 20 Feb 2013 10:41:51 -0800 (PST)
Rajeev Prasad <rp.n...@yahoo.com> wrote:

> hello follwoing code is sending empty email body. I am trying to send
> HTML content in body of mesg. It works if I use a string instead of
> array

So, er, use a string?

Why are you trying to pass an array as the body? What are you
expecting to happen? The argument name even ends in _str - there's a
clue there as to what it's expecting, no?

You can use join() to turn all the elements of the array into a string
- e.g.

body_str => join "\n", @array,

... that would give you all the elements in @array, with a newline
after each.


If, however, you're trying to send a multi-part message, and the array
contains the multiple parts, you want the 'parts' param, not 'body_str'.



--
David Precious ("bigpresh") <dav...@preshweb.co.uk>
http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan www.preshweb.co.uk/github


Rajeev Prasad

unread,
Feb 20, 2013, 2:54:24 PM2/20/13
to David Precious, begi...@perl.org
thx. I did achieve it by using join...

join('',@array)


________________________________
From: David Precious <dav...@preshweb.co.uk>
To: begi...@perl.org
Sent: Wednesday, February 20, 2013 1:01 PM
Subject: Re: Email::Mime not able to send array in mesg body

--
To unsubscribe, e-mail: beginners-...@perl.org
For additional commands, e-mail: beginne...@perl.org
http://learn.perl.org/

Brandon McCaig

unread,
Feb 20, 2013, 4:45:51 PM2/20/13
to Rajeev Prasad, perl list
On Wed, Feb 20, 2013 at 10:41:51AM -0800, Rajeev Prasad wrote:
> hello follwoing code is sending empty email body. I am trying
> to send HTML content in body of mesg. It works if I use a
> string instead of array. I tried sending reference to
> @email_body, but It simply printed array_ref in body.
>
> open(my $tmp_fh,"<",html_file) or die "error: $!";

I will assume that html_file is supposed to be a bareword. :-/

>     @email_body = <$tmp_fh>;
> close $tmp_fh;

See also File::Slurp, which would eliminate this "problem" with
less code than open, <>, close, and join:

use File::Slurp qw/slurp/;

my $email_body = slurp(html_file);

>     my $message = Email::MIME->create(
>       header_str => [
>         From    => '<jo...@apple.com>',
>         To      => '<jac...@banana.com>',
>         Subject => "Please see my test email",
>       ],
>       attributes => {
>         encoding => 'quoted-printable',
>         charset  => 'ISO-8859-1',
>         content_type => 'text/html'
>       },
>       body_str => @email_body,

body_str => $email_body,

>     );
>
>     sendmail($message);

Regards,


--
Brandon McCaig <bamc...@gmail.com> <bamc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

signature.asc

Bill Stephenson

unread,
Feb 20, 2013, 9:02:03 PM2/20/13
to perl list
The "obfuscating code" thread touch on the larger point of selling an app written in perl. I'd like to discuss that a bit because I have some thoughts and questions.

I don't really mind if someone buys my app code and then customizes it for their purposes. That's actually a great thing for the buyer, and if they hired a local perl guy to do that work, that'd be great for all of us.

I don't even mind if they sell add-ons to the app, but I don't want them selling the app.

Is there a GPL type license that allows buyers of code to change it to whatever they want, but restricts their right to resell it. or do I have to make one of those up?

I can't even get through the gutenberg.org license without wanting to bang my head on a wall. Will a simple copyright do the trick?

How do others deal with this? Attorneys? (I hope there is a simpler way)

Kindest Regards,

Bill Stephenson

John SJ Anderson

unread,
Feb 20, 2013, 9:35:07 PM2/20/13
to perl list

On Feb 20, 2013, at 6:02 PM, Bill Stephenson <bi...@ezinvoice.com> wrote:

> The "obfuscating code" thread touch on the larger point of selling an app written in perl. I'd like to discuss that a bit because I have some thoughts and questions.


Putting on my List Mom hat, I have to say that this is off topic for the Perl Beginners list.

I wish I could recommend another more appropriate mailing list, but I can't.

If anybody wishes to respond to this, please take it off list.

thanks,
john - aka the perl-beginners moderator

--
John SJ Anderson // gene...@genehack.org


rjc

unread,
Feb 22, 2013, 4:59:21 AM2/22/13
to begi...@perl.org
Hi Bill,

This is a kind request directed to you but also to everyone else to
consider starting a new thread with a new message sent to the mailing
list rather than replying to a previous email and changing the Subject:
line.

The rationale behind it is the fact that many email clients but also
mailing list archives [0] use "In-Reply-To:" or "References:" for
threading. New threads, and therefore particular emails, are easier to
distinguish or find.

[0] http://www.mail-archive.com/beginners%40perl.org/msg115606.html

Thanks in advance.

Regards,

Raf

Bill Stephenson

unread,
Feb 22, 2013, 2:20:55 PM2/22/13
to perl list
On Feb 22, 2013, at 3:59 AM, rjc wrote:

> Hi Bill,
>
> This is a kind request directed to you but also to everyone else to
> consider starting a new thread with a new message sent to the mailing
> list rather than replying to a previous email and changing the Subject:
> line.
>
> The rationale behind it is the fact that many email clients but also
> mailing list archives [0] use "In-Reply-To:" or "References:" for
> threading. New threads, and therefore particular emails, are easier to
> distinguish or find.

Thank you for the info Raf. I had no idea the client (or the list) was doing that.

I was being lazy...

Kindest Regards,

Bill

rjc

unread,
Feb 23, 2013, 8:00:18 AM2/23/13
to begi...@perl.org
On Fri, Feb 22, 2013 at 07:20:55PM GMT, Bill Stephenson wrote:
> Thank you for the info Raf. I had no idea the client (or the list) was
> doing that.

No worries.

Most people don't know what email headers are, let alone what their
function is.

> I was being lazy...

Aren't we all at times ;^)

> Kindest Regards,
>
> Bill

Regards,

Raf
0 new messages