Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Mail::Sender - authentication and design questions

by Jenda (Abbot)
on Mar 26, 2002 at 13:44 UTC ( [id://154398]=perlquestion: print w/replies, xml ) Need Help??

Jenda has asked for the wisdom of the Perl Monks concerning the following question:

I would like to get some input from the general public on a few issues with Mail::Sender.

1) Will anyone mind if the SendXxxxx() methods will return the Mail::Sender object instead of the 1 they used to?

This would allow chaining the method calls like this :

eval { (new Mail::Sender) ->OpenMultipart({...}) ->Body(...) ->SendEnc(...) ->Part(...) ->SendEnc(...) ->Attach(...) ->Close(); } if ($@ =~ /^Can't call method/) { die "Cannot send mail : $Mail::Sender::Error\n" } elsif ($@) { die $@,"\n"; }
2) There is a beta version that contains code for the SMTP authentication at http://Jenda.Krynicky.cz/Sender.pm . Currently the only supported protocols are LOGIN, PLAIN and CRAM-DM5, but it should be relatively easy to add other ones. Especialy if anyone sends me a snipet of code that implements them ;-)

There is no documentation on this feature yet and the interface is not yet fixed (yes, THIS is the question). In the beta the new Mail::Sender constructor and the Open, OpenMultipart, MailMsg and MailFile methods accepts three new parameters :

auth => the name of the protocol. Only supports LOGIN, PLAIN and CRAM-MD5 now. username => ... password => ...
I wonder whether to use "username" and "password" or "authid" and "authpwd" or something else ...

I do not have access to any server that would implement PLAIN and CRAM-MD5 so could someone test it and let me know? Or create for me a temporary test account on such a server if there are problems so that I could test?

Thanks for opinions, suggestions, bug and success reports and code snipets.

Jenda

== Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ==
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
      -- Rick Osborne, <osborne@gateway.grumman.com>

Replies are listed 'Best First'.
Re: Mail::Sender - design
by Ea (Chaplain) on Mar 26, 2002 at 16:57 UTC
    First of all, let me say I despise you for having the only mail module available for Windoze - hack, pththt - when I'd already written my program to use Mail::Mailer (I'm developing a Windows program under Unix. You gotta problem with that?). I have enough problems with OO as it is.

    Aside from that, the module works fine just talking to a smtp server and I don't use authentication. The only complaint I have is that there is a lot of information in the docs, but it isn't all that clear as to what I could, or should, be doing with this module. /msg me if you want help.

    Performance question: it takes me 5 to 10 seconds to read in an ascii string from a barcode scanner, do 3 Oracle queries and send a short email. Is there a way of making the email sub quicker, a sort of "fire and forget" routine?

    This happens to be the code that gets called after I insert into the database, so that the little darlings get an email receipt for the work they've handed in.

    sub send_receipts { <snip> $sender = new Mail::Sender {smtp => $Mailserver, from => 'CS Handin <kendal>'}; $sender->MailMsg({to => "$userid\@keele.ac.uk", replyto => $handin_manager, subject => 'Receipt for work handed in', msg => $body}); $sender->Close; }
    This gets called by
    if ($receipt_by_email) { defined $email ? send_receipts($email, $descr, &is_work_late($assign)) : aquire_email_info($regno, $assign); }
    A good question to ask at this point is - Is this the Right Thing to Do? Am I taking a hit in speed by using the Windows machine to talk to the SMTP server on the Unix box?

    Lastly, you need more jokes in the documentation. Perhaps, Man who runs behind car becomes exhausted. I'm sorry I won't see you at the next YAPC in Munich to harrass you somemore.

    Ea
    :wq

      1. There are several others that work under Windows. Mail:Sendmail, Net::SMTP, ...

      2. Yes, I agree the docs are not too good. Any suggestions for improvement (or even whole parts rewritten ;-) are appreciated. I guess it would be quicker by email though.

      3. For the performance ... I think there are only two improvements possible. First ... if your script sends several mail messages keep the $sender object. It is NOT connected to the server, but still it would be cheaper. Second ... try to use the IP address instead of the name of the SMTP server.

        The fact that you connect to a Unix server from a Windows machine should not matter much as long as the connection between the two is reasonably quick. Try to telnet to.the.server 25 and see how long it took to get the SMPT server's greeting. If it does take too long you might consider (assuming the windows machine is Win2k or WinNT or WinXP) starting the "Simple Mail Transfer Protocol" service and setting it up to send all emails to that unix box (and restricting the access so that the SMTP on the windows box is only accessible from localhost).

        Let me know if you need help setting this up (I know for sure I WOULD have big problems trying to set up anything like this under Unix.)

      4. As far as the jokes are concerned ... when I wrote the first versions my english was too bad to even understand jokes, let alone write any. And since then I'm only patching and patching and patching ... which makes the docs quite messy actually. :-(

Re: Mail::Sender - authentication and design questions
by projekt21 (Friar) on Mar 27, 2002 at 12:13 UTC

    You may have a look into Net::SMTP_auth where I added authentication for Net::SMTP and contact me for a test account on an SMTP/POP3-Server with those AUTH features.

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste

Re: Mail::Sender - authentication and design questions
by mattr (Curate) on Mar 27, 2002 at 12:56 UTC
    Hello,

    I've used your module in the past. Thank you!

    While I am not knowledgeable about SMTP AUTH format, it sounds like there is another informal protocol being used, in which you can send through a mail server if you first log in. I think dialup providers may be using this. This protocol might be useful too.

    Matt

      Well I know some SMTP servers require that you connect and login via POP3 before allowing you to relay messages. But I don't think it is necessary to provide the POP3 login (or any other type of login) inside Mail::Sender. Since that login happens BEFORE opening the SMTP connection it may be done using other modules or external programs easily. So if you have to login via POP3 you may do something like:
      use Net::POP3; use Mail::Sender; $pop = Net::POP3->new($server); $pop->login( $username, $password) or die "Failed to login!\n"; $pop->quit(); $sender = new Mail::Sender {smtp => $server, ...}; ...
      == Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ==
      Always code as if the guy who ends up maintaining your code
      will be a violent psychopath who knows where you live.
            -- Rick Osborne, osborne@gateway.grumman.com
How to choose a Mailer
by Ea (Chaplain) on Mar 27, 2002 at 13:45 UTC
    The discussion yesterday in the chatterbox about Mail modules started making me think why I had chosen the module I did, way back when. I was in a rush and had to find a replacement module with only the short descriptions available. So, I took a gamble based on my instinct and learned enough about the module to get the job done. Other people's favourites include Mime::Lite and Net::SMTP, neither of which would have occured to me. I'm trying to think why I didn't go for Mail::Sendmail. I must have thought that there could be some problem trying to use it with Exim and didn't want the hassle. Nice docs though.

    Maybe I'm just trying to say that sometimes it feels like there are too many modules on CPAN ;) and sometimes the modules that you could be using (like Net and Mime) aren't listed under the index (Mail and News) which is the first place you look.

    Ea

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://154398]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-25 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found