From: Ted Byers on
I am using Activestate perl 5.10.0 on WXP, if that matters.

I can get all the examples to work properly for trivially simple
emails. However, the following:

MIME::Lite->send('smtp','smtp.gmail.com',AuthUser=>$un, AuthPass=>
$pw, Timeout => 60);

produces the error:

SMTP auth() command not supported on smtp.gmail.com

If I remove the credentials, I get an error about the need to
establish a secure channel, specifically:

SMTP mail() command failed:
5.7.0 Must issue a STARTTLS command first. 11sm9055536vcp.45

Alas, MIME::Lite documentation makes no mention of anything related to
possible issues using stml.gmail.com and thus the question is, "What
needs to be done to set MIME::Lite up to use gmail properly?" A
related question is "What needs to be changed from the usual
configuration in order to use a gmail account that has a domain
different from gmail.com?"

Yes, I did see Email::Send::Gmail, but it is not clear how to use it
in a manner equivalent to:

my $msg = MIME::Lite->new(
From => $sender,
To => $recipient,
Subject => $subject_line,
Type =>'multipart/related'
);
$msg->attach(Type => 'text/html',
Data => $html_template,
);
$msg->attach(Type => 'image/jpg',
Id => 'logo.jpg',
Path => 'template.files/image002.jpg',
);
MIME::Lite->send('smtp','smtp.gmail.com',AuthUser=>$un, AuthPass=>
$pw, Timeout => 60);
$msg->send();

Thanks,

Ted
From: Chris Nehren on
On 2010-06-17, Ted Byers scribbled these curious markings:
> I am using Activestate perl 5.10.0 on WXP, if that matters.

Yes, it does. Everyone using Windows has abandoned ActiveState in favor
of Strawberry. ActiveState Perl is for ActiveState to sell support
contracts and should be treated as such (much as RHELL is for RedHat to
sell support contracts). You should contact your support representative
for help with this issue.

[snip 1995-era MIME::Lite code that doesn't work]

People living in the 21st century write email code using Email::MIME,
Email::Sender, and optionally Email::MIME::Kit. For sending through
Gmail, you'll want Email::Sender::Transport::SMTP::TLS. The example in
the synopsis should get you started. It's specifically written for
Gmail.

--
Thanks and best regards,
Chris Nehren
Unless noted, all content I post is CC-BY-SA.
From: Ted Byers on
On Jun 18, 12:21 am, Chris Nehren <apei...(a)isuckatdomains.net.invalid>
wrote:
> On 2010-06-17, Ted Byers scribbled these curious markings:
>
> > I am using Activestate perl 5.10.0 on WXP, if that matters.
>
> Yes, it does. Everyone using Windows has abandoned ActiveState in favor
> of Strawberry. ActiveState Perl is for ActiveState to sell support
> contracts and should be treated as such (much as RHELL is for RedHat to
> sell support contracts). You should contact your support representative
> for help with this issue.
>
> [snip 1995-era MIME::Lite code that doesn't work]
>
> People living in the 21st century write email code using Email::MIME,
> Email::Sender, and optionally Email::MIME::Kit. For sending through
> Gmail, you'll want Email::Sender::Transport::SMTP::TLS. The example in
> the synopsis should get you started. It's specifically written for
> Gmail.
>
> --
> Thanks and best regards,
> Chris Nehren
> Unless noted, all content I post is CC-BY-SA.

Thanks guys. great. We have progress.

I can now send email in which the body is html, and from a gmail
account to an arbitrary account.

But there is a problem. While the html displays OK, the top haif of
it is repeated at the end. Equally badly, the link between the jpg
file (containing the logo) and the img tag in the html is broken.

The first few lines, showing the package I am using are:

use strict;
use warnings;

use Email::Sender::Transport::SMTP::TLS;
#use Email::Simple::Creator; # or other Email::
use Email::MIME::Creator;
use IO::All;

my $first_name = 'Ted';
my $html_template = slurp_file();
$html_template =~ s/>NAME</>$first_name</;

And, following the examples in the packages' documentation, I made the
following:

my $sender = Email::Sender::Transport::SMTP::TLS->new(
host => 'smtp.gmail.com',
port => 587,
username => 'connie(a)capitalbusinessservices.net',
password => 'cbs2010',
helo => 'capitalbusinessservices.net',
);
my $subject = "A test sending MIME content from gmail to an arbitrary
address (mine)";

my $html_part = Email::MIME->create(
attributes => {
content_type => "text/html",
},
body => "$html_template",
);
my $image_part = Email::MIME->create(
attributes => {
content_type => "image/jpg",
name => "logo.jpg",
},
body => io( "template.files/image002.jpg" )->all,
);
my @parts = ($html_part,$image_part);
my $message = Email::MIME->create(
header => [
From => 'connie(a)capitalbusinessservices.net',
To => 'r.ted.byers(a)gmail.com',
Subject => $subject,
],
parts => \@parts,
);

eval {
$sender->send($message, {
from => 'connie(a)capitalbusinessservices.net',
to => [ 'r.ted.byers(a)gmail.com' ],
} );
};
die "Error sending email: $@" if $@;

It could hardly be simpler.

The img tag is:

<img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025">

I have undoubtedly missed something in making each of the parts, but I
have yet to find what. What I see of the image suggests that
"io( "template.files/image002.jpg" )->all" loses half of the jpeg file
(only half of the image is visible in the attachment, even though the
image is intact if I use my image editor to view it).

Any information you can provide as to what I missed would be
appreciated.

Thanks

Ted
From: Ben Morrow on

Quoth Ted Byers <r.ted.byers(a)gmail.com>:
>
> I can now send email in which the body is html, and from a gmail
> account to an arbitrary account.
>
> But there is a problem. While the html displays OK, the top haif of
> it is repeated at the end. Equally badly, the link between the jpg
> file (containing the logo) and the img tag in the html is broken.
>
> The first few lines, showing the package I am using are:
>
> use strict;
> use warnings;
>
> use Email::Sender::Transport::SMTP::TLS;
> #use Email::Simple::Creator; # or other Email::
> use Email::MIME::Creator;
> use IO::All;
>
> my $first_name = 'Ted';
> my $html_template = slurp_file();

Have you printed out $html_template to verify it contains what you think
it does?

> $html_template =~ s/>NAME</>$first_name</;
>
> And, following the examples in the packages' documentation, I made the
> following:
>
> my $sender = Email::Sender::Transport::SMTP::TLS->new(
> host => 'smtp.gmail.com',
> port => 587,
> username => 'connie(a)capitalbusinessservices.net',
> password => 'cbs2010',

I sincerely hope this isn't your actual password. If it is, change it
*right* *now*.

> helo => 'capitalbusinessservices.net',

Are you sending this from a machine called capitalbusinessservices.net?
If not you should not be claiming you are. In any case, it's probably
better to let HELO/EHLO default to your machine's actual hostname.

> );
> my $subject = "A test sending MIME content from gmail to an arbitrary
> address (mine)";
>
> my $html_part = Email::MIME->create(
> attributes => {
> content_type => "text/html",
> },
> body => "$html_template",

Those quotes don't do anything for you. See perldoc -q quote.

> );
> my $image_part = Email::MIME->create(
> attributes => {
> content_type => "image/jpg",
> name => "logo.jpg",
> },
> body => io( "template.files/image002.jpg" )->all,

Have you tried this without IO::All? Since a JPEG is a binary file, are
you reading the file in binmode, if that matters?

> );
> my @parts = ($html_part,$image_part);
> my $message = Email::MIME->create(
> header => [
> From => 'connie(a)capitalbusinessservices.net',
> To => 'r.ted.byers(a)gmail.com',
> Subject => $subject,
> ],
> parts => \@parts,
> );
>
> eval {
> $sender->send($message, {
> from => 'connie(a)capitalbusinessservices.net',
> to => [ 'r.ted.byers(a)gmail.com' ],
> } );
> };
> die "Error sending email: $@" if $@;

It's safer to write this like

eval {
$sender->send(...);
1;
} or die "...";

There are circumstances under which $@ can be cleared between the end of
the eval and the start of the next statement (signal handlers, for
instance) and it's important to know there was an error even if you've
lost the message by then. (Yes, this is annoying, and generally regarded
as a flaw in Perl's exception mechanism.) You may also want to look at
Try::Tiny, which handles the unpleasant details for you.

> It could hardly be simpler.
>
> The img tag is:
>
> <img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025">

What happens if you take out that v:shapes attribute? It's not HTML.

> I have undoubtedly missed something in making each of the parts, but I
> have yet to find what. What I see of the image suggests that
> "io( "template.files/image002.jpg" )->all" loses half of the jpeg file
> (only half of the image is visible in the attachment, even though the
> image is intact if I use my image editor to view it).

When you say 'in the attachment' do you mean 'embedded in the HTML
section of the message'? What happens if you save just the JPEG
somewhere and compare it to the original file: are they identical?

Are you using IE/Outlook/something else MS to view the email? ISTR that
v:shapes attribute is something Word puts in HTML; possibly it's causing
mshtml to display only part of the image. What happens if you use a
different browser? What happens if you just view the original HTML file,
without incorporating it into an email?

Ben

From: Peter J. Holzer on
On 2010-06-18 22:22, Ted Byers <r.ted.byers(a)gmail.com> wrote:
> While the html displays OK, the top haif of it is repeated at the end.
> Equally badly, the link between the jpg file (containing the logo) and
> the img tag in the html is broken.
>
> The first few lines, showing the package I am using are:
[...]
> use Email::MIME::Creator;
[...]
> my $html_part = Email::MIME->create(
> attributes => {
> content_type => "text/html",
> },
> body => "$html_template",
> );
> my $image_part = Email::MIME->create(
> attributes => {
> content_type => "image/jpg",
> name => "logo.jpg",
> },
> body => io( "template.files/image002.jpg" )->all,
> );
> my @parts = ($html_part,$image_part);
> my $message = Email::MIME->create(
> header => [
> From => 'connie(a)capitalbusinessservices.net',
> To => 'r.ted.byers(a)gmail.com',
> Subject => $subject,
> ],
> parts => \@parts,
> );
[...]
> It could hardly be simpler.
>
> The img tag is:
>
><img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025">

That doesn't work. You cannot use a relative URL like "logo.jpg" in an
email. You can either use an http: URL (but many mailers won't resolve
them by default for privacy reasons (google "web bugs" for details)) or
a cid: URL to refer to an image within the email (this is a better idea
and obviously what you are trying to do). To use cid: URLs, all the
related parts of the message (in this case the HTML part and the image)
need to be enclosed in a multipart/related message. You don't seem to do
that.

Here is an example using MIME::Lite to build an HTML mail with embedded
images. Adapting it to Email::MIME::Creator is left as an exercise to
the reader:

#!/usr/bin/perl
use warnings;
use strict;

use MIME::Lite;

my $msg = MIME::Lite->new(
From => 'hjp-usenet2(a)hjp.at',
To => 'hjp-usenet2(a)hjp.at',
Subject => 'HTML test message',
Type => 'multipart/related; type=text/html',
);

my $unique = time();
my $tb_logo_cid = "tb-logo.$unique\@hjp.at";
my $smiley_cid = "smiley.$unique\@hjp.at";

$msg->attach(
Type => 'text/html; charset=UTF-8',
Data => "<title>Message text</title>\n" .
"<h1>Hallo</h1>\n" .
"<p>Hier ist ein Text mit einem Bild:</p>\n" .
"<p><img alt='TB Logo' src='cid:$tb_logo_cid'></p>\n" .
"<p>Es funktioniert! <img alt=':-)' src='cid:$smiley_cid'></p>\n",
);

my $part = MIME::Lite->new(
Type => 'image/png',
Path => 'Mozilla_Thunderbird_logo.png',
);
$part->attr('Content-Id', "<$tb_logo_cid>");
$msg->attach($part);

$part = MIME::Lite->new(
Type => 'image/gif',
Path => 'smiley16.gif',
);
$part->attr('Content-Id', "<$smiley_cid>");
$msg->attach($part);


$msg->print(\*STDOUT);
__END__

hp