Discussion:
Sending email w/Mail::Builder::Simple -- need help
Dennis G. Wicks
2009-02-24 17:39:57 UTC
Permalink
Greetings;

Here's the code:

-----------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;
use Mail::Builder::Simple;
my $mail = Mail::Builder::Simple->new;

# Send the email with an SMTP server:
$mail->send(
mail_client => {
mailer => 'SMTP',
mailer_args => [
Host => 'smtpout.secureserver.net',
username => '***@mgssub.com',
password => 'mypasswd',
],
},
from => '***@mgssub.com',
to => '***@gmail.com',
subject => 'The subject with UTF-8 chars',
plaintext => "Hello,\n\nHow are you?\n",
);
--------------------------------------------------------------------
It doesn't look like I am sending any mail. I get no error
messages when I run this from my personal (not root) login.

I use Thunderbird as my mail program and it can send mail
both ways between those two addresses.

Lacking any problems with the code, does anybody have any
ideas about what may be stopping this from working?

Many TIA!
Dennis
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-24 18:09:43 UTC
Permalink
Post by Dennis G. Wicks
#!/usr/bin/perl
use strict;
use warnings;
use Mail::Builder::Simple;
my $mail = Mail::Builder::Simple->new;
$mail->send(
mail_client => {
mailer => 'SMTP',
mailer_args => [
Host => 'smtpout.secureserver.net',
password => 'mypasswd',
],
},
subject => 'The subject with UTF-8 chars',
plaintext => "Hello,\n\nHow are you?\n",
);
--------------------------------------------------------------------
It doesn't look like I am sending any mail. I get no error messages when I
run this from my personal (not root) login.
I use Thunderbird as my mail program and it can send mail both ways
between those two addresses.
Lacking any problems with the code, does anybody have any ideas about what
may be stopping this from working?
Many TIA!
Dennis
The code looks fine. There could be the following problems:
- If you have the SMTP server locally, it doesn't require authentication, or
- The username should not be ***@mgssub.com but only tfrg, or
- The server requires SSL encryption (like Gmail's SMTP server), or
- the message is sent by it reaches in the SPAM folder.

Make sure you have the latest version of the module, although I don't know
this is importint for the current issue.

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-24 18:41:44 UTC
Permalink
<snip>
Post by Octavian Râsnita
Post by Dennis G. Wicks
Lacking any problems with the code, does anybody have any ideas about
what may be stopping this from working?
- If you have the SMTP server locally, it doesn't require
authentication, or
- The server requires SSL encryption (like Gmail's SMTP server), or
- the message is sent by it reaches in the SPAM folder.
Is there no way to have the module report the nature of the problem?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Dennis G. Wicks
2009-02-24 18:55:24 UTC
Permalink
Post by Gunnar Hjalmarsson
<snip>
Post by Octavian Râsnita
Post by Dennis G. Wicks
Lacking any problems with the code, does anybody have any ideas about
what may be stopping this from working?
- If you have the SMTP server locally, it doesn't require
authentication, or
- The server requires SSL encryption (like Gmail's SMTP server), or
- the message is sent by it reaches in the SPAM folder.
Is there no way to have the module report the nature of the problem?
I haven't found a any way to do that.

But I think I have discovered the problem. The SMTP server
requires a non-standard port. I have searched the doc and I
don't find anything that tells me how to pass a port # to
the module. Anybody know how to do that?

(BTW: Everything else is set up exactly as in Tbird.)

tnx,
Dennis
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-24 19:23:02 UTC
Permalink
But I think I have discovered the problem. The SMTP server requires a
non-standard port. I have searched the doc and I don't find anything
that tells me how to pass a port # to the module. Anybody know how to do
that?
I don't; the below suggestion is merely a shot in the dark.

mailer_args => [
Host => 'smtpout.secureserver.net',
username => '***@mgssub.com',
password => 'mypasswd',
port => 24, # or whatever...
],
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-24 20:31:37 UTC
Permalink
But I think I have discovered the problem. The SMTP server requires a
non-standard port. I have searched the doc and I don't find anything that
tells me how to pass a port # to the module. Anybody know how to do that?
(BTW: Everything else is set up exactly as in Tbird.)
Oh yes, I think I have forgotten to add details about how to use a different
port in the POD docs. You need to add the port after the SMTP server like:

Host => 'smtp.host.com:28'

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-24 19:07:01 UTC
Permalink
Post by Gunnar Hjalmarsson
<snip>
Post by Octavian Râsnita
Post by Dennis G. Wicks
Lacking any problems with the code, does anybody have any ideas about
what may be stopping this from working?
- If you have the SMTP server locally, it doesn't require authentication, or
- The server requires SSL encryption (like Gmail's SMTP server), or
- the message is sent by it reaches in the SPAM folder.
Is there no way to have the module report the nature of the problem?
--
Gunnar Hjalmarsson
I've tried to see if I can make it report the problems, but I couldn't do
it.
The module uses Mail::Builder which uses Email::Send, and Email::Send
doesn't report too many things.

I've seen that the maintainer of Email::Send is developing a new module
named Email::Sender, because he considers that Email::Send has some bugs,
however until that new module will be ready... I need to use Email::Send,
because it allows sending in many ways, using SMTP, Sendmail, Qmail, Google
and a few others.

It is pretty strange that even though Perl is great, there is no "great"
module for sending email that can do at least what Outlook Express can do
under Windows, that doesn't have errors, work with SMTP over TLS, SSL and
other ways of sending email.

If somebody knows a better module for sending email, please tell us.

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-24 22:14:57 UTC
Permalink
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
- If you have the SMTP server locally, it doesn't require
authentication, or
- The server requires SSL encryption (like Gmail's SMTP server), or
- the message is sent by it reaches in the SPAM folder.
Is there no way to have the module report the nature of the problem?
I've tried to see if I can make it report the problems, but I couldn't
do it.
Hmm.. Not good.
Post by Octavian Râsnita
The module uses Mail::Builder which uses Email::Send, and Email::Send
doesn't report too many things.
I've seen that the maintainer of Email::Send is developing a new module
named Email::Sender, because he considers that Email::Send has some
bugs, however until that new module will be ready... I need to use
Email::Send, because it allows sending in many ways, using SMTP,
Sendmail, Qmail, Google and a few others.
Why is it important to have a mail sending module hunt for various
mailer programs?

My personal favorite is Jenda's Mail::Sender. This is an example of how
that module might be used to send the OP's message:

#!/usr/bin/perl
use strict;
use warnings;
use Mail::Sender;

ref (new Mail::Sender -> MailMsg( {
smtp => 'smtpout.secureserver.net',
port => '24', # or whatever
auth => 'LOGIN',
authid => '***@mgssub.com',
authpwd => 'mypasswd',
from => '***@mgssub.com',
to => '***@gmail.com',
subject => 'The subject with chars corresp. to the charset',
msg => "Hello,\n\nHow are you?\n",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-24 22:59:03 UTC
Permalink
Post by Octavian Râsnita
however until that new module will be ready... I need to use Email::Send,
because it allows sending in many ways, using SMTP, Sendmail, Qmail,
Google and a few others.
Why is it important to have a mail sending module hunt for various mailer
programs?
It is important because some users might want to use Sendmail, some Qmail,
some an SMTP server, some Gmail or other methods. The best email client
would need to be able to use any method.
My personal favorite is Jenda's Mail::Sender. This is an example of how
#!/usr/bin/perl
I have also used this module, but I had some issues with it when I needed to
use special UTF-8 chars in the program.

First, Mail::Sender is too low level so I've used Mail::Sender::Easy which
was much easier to use. Mail::Sender::Easy is based on Mail::Sender.

Mail::Sender doesn't encode the headers to UTF-8 and we would need to do
that MIME encoding explicitly which is something I wouldn't like. If you put
some chars like astâîASTÂÎ in any header of the message like the To:, From:
or the subject of the message, the message might not be sent because it
might be blocked due to the fact that the headers are not encoded well.

This happends no matter if I use "use utf8;" in the program or not.

Then Mail::Sender doesn't support creating the messages or the attachments
from templates and I guess it also doesn't encode the body of the message to
UTF-8 and we would need to do it explicitly.

For simple things however, Mail::Sender::Easy is good.

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Dennis G. Wicks
2009-02-25 00:59:18 UTC
Permalink
[Cleaned out previous stuff]

Greetings;

Well, I tried to attach the port to the server address,

Host => 'smtpout.secureserver.net:3535',

but that doesn't work either. Maybe there is something else
setup wrong that I'm not seeing.

I also was going to try Mail::Sender but I can't get a clean
install. Haven't looked too close at that yet.

Also, there are a few of the new Email::Sender modules
available. I am going to checkout
Email::Sender::Transport::SMTP and see if that is more
verbose than the older version.

Thanks for the help, and let me know if you get any more
insights into the problem.

Thanks again,
Dennis
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-25 07:26:30 UTC
Permalink
Post by Dennis G. Wicks
[Cleaned out previous stuff]
Greetings;
Well, I tried to attach the port to the server address,
Host => 'smtpout.secureserver.net:3535',
but that doesn't work either. Maybe there is something else setup wrong
that I'm not seeing.
I see the word "secure" in the host of the server. The server might be
secured and it could use SSL or TLS encryptions for communicating with it.

If it does this, you can try to use something like:

use strict;
use Mail::Builder::Simple;
use Net::SMTP::SSL; #or TLS

my $mail = Mail::Builder::Simple->new;

$mail->send(
mail_client => {
mailer => 'SMTP',
mailer_args => [
Host => 'smtpout.secureserver.net:3535',
ssl => 1,
username => 'the_username',
password => 'the_pass',
],
},
from => ['***@host.com', 'Your Name'],
to => ['***@anotherhost.com', 'Recipient Name'],
subject => 'The subject',
plaintext => "The text\n\n",
);

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-25 02:37:06 UTC
Permalink
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
however until that new module will be ready... I need to use
Email::Send, because it allows sending in many ways, using SMTP,
Sendmail, Qmail, Google and a few others.
Why is it important to have a mail sending module hunt for various
mailer programs?
It is important because some users might want to use Sendmail, some
Qmail, some an SMTP server, some Gmail or other methods. The best email
client would need to be able to use any method.
Everyone must use an SMTP server. How many are really interested in what
happens behind the scenes between the module and the server, as long as
it works?
Post by Octavian Râsnita
Mail::Sender doesn't encode the headers to UTF-8 and we would need to do
that MIME encoding explicitly which is something I wouldn't like.
<snip>
Post by Octavian Râsnita
Then Mail::Sender ... doesn't encode the body
of the message to UTF-8 and we would need to do it explicitly.
Well, if I understand it correctly, Mail::Builder::Simple *enforces* the
use of UTF-8, which is something I don't like.

This code works, and the message is displayed just fine in my email client:

use Mail::Sender;
ref (new Mail::Sender -> MailMsg( {
smtp => 'localhost',
charset => 'ISO-8859-1',
from => '"Pär" <***@example.com>',
to => 'me <***@example.com>',
subject => 'Östra Vägen',
msg => "Hello,\n\nWondering about Östra Vägen.\n",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";

When trying to send the same message using Mail::Builder::Simple, I
encountered two problems:

1) I couldn't find a way to change the charset.

2) Mail::Builder objected, claiming that my stated "From:" address

"Pär" <***@example.com>

is not valid (which is something I don't understand).
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-25 06:31:31 UTC
Permalink
Post by Gunnar Hjalmarsson
Well, if I understand it correctly, Mail::Builder::Simple *enforces* the
use of UTF-8, which is something I don't like.
Well, I like that, because it is more simple to send special chars from more
languages, but without needing to know nor to specify the charset explicitly
when creating the message.
Post by Gunnar Hjalmarsson
use Mail::Sender;
ref (new Mail::Sender -> MailMsg( {
smtp => 'localhost',
charset => 'ISO-8859-1',
subject => 'Östra Vägen',
msg => "Hello,\n\nWondering about Östra Vägen.\n",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";
I have tried to use the same code but I've changed the charset to UTF-8
(also tried utf8) and the subject to:

subject => 'Östra Vägen astâîASTÂÎ',

But instead of this subject, in the message appears:

Östra Vägen astâîAST=Î



(It appear a "=" sign instead of Â, even though when used in another
context, Â appears well.)



And when I see the message subject in the list of messages (in Outlook
Express), the subject appears as:

Ã-stra Vägen ÄfÅYţâîÄ,ÅzÅ¢Ã=,ÃZ



So there should be some bugs in Mail::Sender or the module it uses for
encoding the headers.


Of course, that bad encoded header appeared when I didn't used "use utf8;"
in my program even though I should use it, because if I add "use utf8;",
then the program doesn't work at all, and gives the following error:

Wide character in subroutine entry at E:/perl510/site/lib/Mail/Sender.pm
line 148, <GEN0> line 12.

So I can't send well UTF-8 encoded messages using Mail::Sender.

I already use Mail::Sender::Easy, but I've abandoned using it for the
reasons above.
Post by Gunnar Hjalmarsson
When trying to send the same message using Mail::Builder::Simple, I
1) I couldn't find a way to change the charset.
Why would you want to change the charset? The same text could be sent as
UTF-8, and the message could also contain chars from other languages which
are not defined in ISO-8859-1, and you won't need to specify any charset
explicitly.
Post by Gunnar Hjalmarsson
2) Mail::Builder objected, claiming that my stated "From:" address
is not valid (which is something I don't understand).
It tells you this because the syntax for using it with Mail::Builder::Simple
is different. You need to use:

from => ['***@example.com', 'Pär'],

This way you don't need to interpolate the scalar vars in a string if you
need to get them from a database for example because you can do:

from => [$email, $name],

I also don't like that Mail::Sender ads strange headers to the mail messages
and I don't know why it does this.
If someone really wants to use it for sending spam, he can change
Mail::Sender very easy and can send spam without any problem...

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-25 15:06:19 UTC
Permalink
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
Well, if I understand it correctly, Mail::Builder::Simple *enforces*
the use of UTF-8, which is something I don't like.
Well, I like that, because it is more simple to send special chars from
more languages, but without needing to know nor to specify the charset
explicitly when creating the message.
Ok, then we are simply not agreed on this one.
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
use Mail::Sender;
ref (new Mail::Sender -> MailMsg( {
smtp => 'localhost',
charset => 'ISO-8859-1',
subject => 'Östra Vägen',
msg => "Hello,\n\nWondering about Östra Vägen.\n",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";
I have tried to use the same code but I've changed the charset to UTF-8
subject => 'Östra Vägen astâîASTÂÎ',
If you change the charset to UTF-8, you'd better also pass UTF-8 encoded
strings to the module. That's not a UTF-8 string.

<snip>
Post by Octavian Râsnita
So there should be some bugs in Mail::Sender or the module it uses for
encoding the headers.
As far as I know, Mail::Sender does not encode the headers, but I
wouldn't call that a bug. It just means that unless the subject line is
ISO-8859-1 (or ASCII), you need to encode it using quoted-printable or
base64.

In my experience, Mail::Sender sends messages with any encoding. This
code works for me:

use Mail::Sender;
ref (new Mail::Sender -> MailMsg( {
smtp => 'localhost',
charset => 'UTF-8',
from => '"Pär" <***@example.com>',
to => 'me <***@example.com>',
subject => '=?UTF-8?Q?' .
MIME::QuotedPrint::encode('Östra Vägen', '') . '?=',
msg => "Hello,\n\nWondering about Östra Vägen.\n",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
When trying to send the same message using Mail::Builder::Simple, I
<snip>
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
2) Mail::Builder objected, claiming that my stated "From:" address
is not valid (which is something I don't understand).
It tells you this because the syntax for using it with
Ok, thanks. The automatic encoding of headers with non-ASCII characters
is nice, but Mail::Builder::Simple is still not very useful to me, since
it only permits UTF-8 encoded strings.
Post by Octavian Râsnita
I also don't like that Mail::Sender ads strange headers to the mail
messages and I don't know why it does this.
It doesn't if you say

$Mail::Sender::NO_X_MAILER = 1;

<snip>
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râsnita
2009-02-25 16:05:22 UTC
Permalink
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
I have tried to use the same code but I've changed the charset to UTF-8
subject => 'Östra Vägen astâîASTÂÎ',
If you change the charset to UTF-8, you'd better also pass UTF-8 encoded
strings to the module. That's not a UTF-8 string.
If I used it in a UTF-8 encoded perl program and was also using "use utf8;"
in it, I expected that it understand that it should be encoded to UTF-8.
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
So there should be some bugs in Mail::Sender or the module it uses for
encoding the headers.
As far as I know, Mail::Sender does not encode the headers, but I wouldn't
call that a bug. It just means that unless the subject line is ISO-8859-1
(or ASCII), you need to encode it using quoted-printable or base64.
Well, instead of the old type encoding of ISO-8859-1, it would have been
much better if it would encode to UTF-8 and also do the MIME encoding.
Post by Gunnar Hjalmarsson
In my experience, Mail::Sender sends messages with any encoding. This code
use Mail::Sender;
ref (new Mail::Sender -> MailMsg( {
smtp => 'localhost',
charset => 'UTF-8',
subject => '=?UTF-8?Q?' .
MIME::QuotedPrint::encode('Östra Vägen', '') . '?=',
msg => "Hello,\n\nWondering about Östra Vägen.\n",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";
Well, I think it is too low level to need to explicitly do the MIME
encoding...
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
It tells you this because the syntax for using it with
Ok, thanks. The automatic encoding of headers with non-ASCII characters is
nice, but Mail::Builder::Simple is still not very useful to me, since it
only permits UTF-8 encoded strings.
Yes I know this, but since any char from any language can be found in the
UTF-8 encoding, I don't think this is such a big issue... unless you need to
modify an old code.
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
I also don't like that Mail::Sender ads strange headers to the mail
messages and I don't know why it does this.
It doesn't if you say
$Mail::Sender::NO_X_MAILER = 1;
Oh sorry, I was using Mail::Sender::Easy because it has a much nicer syntax
than Mail::Sender, and Mail::Sender::Easy also adds some headers that can't
be disabled with a configuration.

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-25 17:15:57 UTC
Permalink
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
I have tried to use the same code but I've changed the charset to
subject => 'Östra Vägen astâîASTÂÎ',
If you change the charset to UTF-8, you'd better also pass UTF-8
encoded strings to the module. That's not a UTF-8 string.
If I used it in a UTF-8 encoded perl program and was also using "use
utf8;" in it, I expected that it understand that it should be encoded to
UTF-8.
I don't think that's what the utf8 pragma is about. (But, as I'm sure
you understand, my UTF-8 knowledge is limited.)

perldoc utf8
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
As far as I know, Mail::Sender does not encode the headers, but I
wouldn't call that a bug. It just means that unless the subject line
is ISO-8859-1 (or ASCII), you need to encode it using quoted-printable
or base64.
Well, instead of the old type encoding of ISO-8859-1, it would have been
much better if it would encode to UTF-8 and also do the MIME encoding.
AFAIK, no mail sending module automatically *encodes to UTF-8*. But I
agree that MIME encoding of certain headers would have been nice.
Post by Octavian Râsnita
Post by Gunnar Hjalmarsson
... Mail::Builder::Simple is still not very useful
to me, since it only permits UTF-8 encoded strings.
Yes I know this, but since any char from any language can be found in
the UTF-8 encoding, I don't think this is such a big issue... unless you
need to modify an old code.
There is - and will be in the foreseeable future - quite a lot of text
in this world that is not UTF-8 encoded. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-25 17:42:47 UTC
Permalink
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
If I used it in a UTF-8 encoded perl program and was also using "use
utf8;" in it, I expected that it understand that it should be encoded
to UTF-8.
I don't think that's what the utf8 pragma is about. (But, as I'm sure
you understand, my UTF-8 knowledge is limited.)
perldoc utf8
This is an example program where "use utf8;" makes a difference:

use utf8;
$igår = '2009-02-24';
print "Yesterday: $igår\n";

("igår" is Swedish for "yesterday")
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-25 17:50:54 UTC
Permalink
[ new attempt - encoding is tricky... ]
Post by Gunnar Hjalmarsson
Post by Octavian Râsnita
If I used it in a UTF-8 encoded perl program and was also using "use
utf8;" in it, I expected that it understand that it should be encoded
to UTF-8.
I don't think that's what the utf8 pragma is about. (But, as I'm sure
you understand, my UTF-8 knowledge is limited.)
perldoc utf8
This is an example program where "use utf8;" makes a difference:

use utf8;
$igår = '2009-02-24';
print "Yesterday: $igår\n";

("igår" is Swedish for "yesterday")
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Octavian Râşniţă
2009-02-25 20:11:44 UTC
Permalink
Post by Gunnar Hjalmarsson
[ new attempt - encoding is tricky... ]
Post by Octavian Râsnita
If I used it in a UTF-8 encoded perl program and was also using "use
utf8;" in it, I expected that it understand that it should be encoded to
UTF-8.
I don't think that's what the utf8 pragma is about. (But, as I'm sure you
understand, my UTF-8 knowledge is limited.)
perldoc utf8
use utf8;
$igår = '2009-02-24';
print "Yesterday: $igår\n";
("igår" is Swedish for "yesterday")
--
Gunnar Hjalmarsson
Well I have tried the scripts from the 2 messages, but I must admit that I
don't understand what I should look for.
Both of them print the same thing, no matter if I use "use utf8;" or not....

Octavian
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-25 21:06:44 UTC
Permalink
Post by Octavian Râşniţă
Post by Octavian Râsnita
use utf8;
$igår = '2009-02-24';
print "Yesterday: $igår\n";
("igår" is Swedish for "yesterday")
Well I have tried the scripts from the 2 messages, but I must admit that
I don't understand what I should look for.
Both of them print the same thing, no matter if I use "use utf8;" or not....
$ cat test1.pl
$igår = '2009-02-24';
print "Yesterday: $igår\n";
$ cat test2.pl
use utf8;
$igår = '2009-02-24';
print "Yesterday: $igår\n";
$ perl test1.pl
Unrecognized character \xC3 in column 4 at test1.pl line 1.
$ perl test2.pl
Yesterday: 2009-02-24
$

The variable name, which actually is $igår, is UTF-8 encoded in the
scripts. Enabling the utf8 pragma makes Perl allow that.

HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Dennis G. Wicks
2009-02-26 01:23:38 UTC
Permalink
We now return you to the original problem!

I got the sample that Gunnar posted using Mail::Sender to
work after I played around with cpan and got it installed.

Now I have discovered a new problem. The SMTP server does
not respond on the first try all the time. (I think this is
a local problem, but I need to replace my gateway/firewall
server to solve ti.) It returns a message

Cannot send mail: Service not available. Reply:

This comes from the internals of Mail::Sender. I found the
place and it is trying to print some status code or return
code right after "Reply:" but there isn't anything there.
This is probably why the error exit at the end of the my
test code isn't triggered.

Here is my code:

ref (new Mail::Sender -> MailMsg( {
smtp => 'smtpout.secureserver.net',
port => '3535', # or whatever
auth => 'LOGIN',
authid => '***@mgssub.com',
authpwd => 'mypasswd',
from => '***@mgssub.com',
to => '***@wicksclan.com',
subject => 'Yet another test!',
msg => "$msg",
} )) or die "Cannot send mail: $Mail::Sender::Error\n";

Now the question is, how can I trap that error message from
the Mail::Sender module and repeat as needed?

Thanks for all the help!
Dennis
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-02-26 07:08:32 UTC
Permalink
Post by Dennis G. Wicks
We now return you to the original problem!
What's that about? Oh, yeah... ;-)
Post by Dennis G. Wicks
I got the sample that Gunnar posted using Mail::Sender to work after I
played around with cpan and got it installed.
Now I have discovered a new problem. The SMTP server does not respond on
the first try all the time. (I think this is a local problem, but I need
to replace my gateway/firewall server to solve ti.) It returns a message
<snip>
Post by Dennis G. Wicks
Now the question is, how can I trap that error message from the
Mail::Sender module and repeat as needed?
Try this:

my $sender = Mail::Sender->new( {
smtp => 'smtpout.secureserver.net',
port => '3535',
from => '***@mgssub.com',
} );
ref $sender or die
"Object creation failed: $Mail::Sender::Error\n";

for my $try (1..4) {
if ( ref( $sender->MailMsg( {
auth => 'LOGIN',
authid => '***@mgssub.com',
authpwd => 'mypasswd',
to => '***@wicksclan.com',
subject => 'Yet another test!',
msg => $msg,
} ) ) ) {
print "Message was sent.\n";
last;
} else {
warn "Send attempt $try. $sender->{'error_msg'}\n";
$try == 4 ? die 'I give up' : sleep 10;
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Gunnar Hjalmarsson
2009-03-04 17:11:28 UTC
Permalink
The discussion in this thread made me realize that I'd better update my
own mail related module, CGI::ContactForm, as regards MIME encoding. An
updated version has been uploaded to CPAN.

http://search.cpan.org/dist/CGI-ContactForm/
Post by Octavian Râsnita
Mail::Sender doesn't encode the headers to UTF-8 and we would need to do
that MIME encoding explicitly which is something I wouldn't like.
It's not that difficult. The key code I used in CGI::ContactForm is a
function named mimeencode(). This code illustrates how a header is being
prepared before it's passed to Mail::Sender:

use MIME::QuotedPrint;

my $subject = 'Smörgåsbord';
$subject = mimeencode($subject, 'UTF-8');
print "$subject\n";

sub mimeencode {
my ($str, $enc) = @_;
return $str unless $str =~ /[[:^ascii:]]/;
my @parts;
while ( $str =~ /(.{1,40}.*?(?:\s|$))/g ) {
my $part = $1;
push @parts, MIME::QuotedPrint::encode($part, '');
}
join "\r\n\t", map { "=?$enc?Q?$_?=" } @parts;
}

The resulting output is:

=?UTF-8?Q?Sm=C3=B6rg=C3=A5sbord?=
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Continue reading on narkive:
Loading...