Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to send mail from Perl/Tk Program?

by Corion (Pope)
on Apr 10, 2007 at 12:52 UTC ( #609126=note: print w/ replies, xml ) Need Help??


in reply to How to send mail from Perl/Tk Program?

What part of the MIME::Lite documentation makes you think it is for CGI scripts only? I use MIME::Lite in scripts that send mail quite often, and well outside any webbish environment.


Comment on Re: How to send mail from Perl/Tk Program?
Re^2: How to send mail from Perl/Tk Program?
by mikasue (Friar) on Apr 10, 2007 at 13:12 UTC
    Oh I see. However when I run the following code:
    use strict; use warnings; use Tk; use MIME::Lite; my $MW = MainWindow->new(-background=>'white'); $MW->geometry('400x350+250+100'); my $msg = MIME::Lite->new( From =>'youremail@netzero.com', To =>'youremail@email.com', Subject =>'Helloooooo, USER!', Data =>"This is a test email from my Perl/Tk prog +ram. Enjoy!" ); $MW->Button(-text=>'Test Email to Parent', -background=>'green', -font +=>'Arial 14', -foreground=>'blue', -command=>sub{$msg->send;} )->pack +(-side=>'left', -anchor=>'w', -padx=>'50'); MainLoop;
    I get the following error message:

    'sendmail' is not recognized as an internal or external command, operable program or batch file.

    I thought 'sendmail' was a unix program. I am on a Windows system.

    Thanks

      Maybe you want to change how messages are sent?

      You will still need a working SMTP server that is willing to accept your email - most likely your ISP provides one for you.

        I thought about this Corion. But I want this to work on other users machines. I dont' want to hardcode my SMTP server in my program and then it doesn't work for another user.

        Any suggestions on making smtp universal to all my users?

      You'll need to change that, then :-) Further down in the doc, there's this section:
      Change how messages are sent ### Do something like this in your 'main': if ($I_DONT_HAVE_SENDMAIL) { MIME::Lite->send('smtp', "smtp.myisp.net", Timeout=>60); } ### Now this will do the right thing: $msg->send; ### will now use Net::SMTP as shown above
      Hope that points you in the right direction :-)

      Update: Wow. Two other answers as I was typing up this one :-D

      on windows there is no sendmail program(unless you're
      on cygwin but probably you're not)
      use Email::Send
      for sending email ,it should work ok.
        But you still need to do some configuration for the SMTP host and maybe the authentication.

        Another possibility is to send mail via the web browser, in the hope that the user already configured the browser to send mail. The downside is that it is necessary to acknowledge the mail outside of the Tk program. For example, this works on my Unix system with seamonkey:

        seamonkey 'mailto:bla@example.com?subject=Subject&body=the%20body%20of +%20the%20mail'

      And what if I'm looking for a different approach?

      I want a link that do the same as sendto:mymail@server.com. In other words, that call the standard mail program of the user.

      thanks,

      memo.garciasir@gmail.com

        You could put hyperlinks in your Text widgets, that run the mail program, when clicking on the hypertext link. An example, without the actual mailcode....which should be forked off or threaded.
        #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new( -title => "hyperlinks" ); my $t = $mw->Scrolled('Text')->pack; my $tag = "tag000"; foreach (<DATA>) { chomp; my (@items) = split (/(http:\S+)/,$_); foreach (@items) { if (/(http:\S+)/) { $t->insert( 'end', $_, $tag ); $t->tagConfigure( $tag, -foreground => 'blue' ); $t->tagBind( $tag, '<Any-Enter>' => [ \&manipulate_link, $tag, 'raised', +'hand2' ] ); $t->tagBind( $tag, '<Any-Leave>' => [ \&manipulate_link, $tag, 'flat', 'x +term' ] ); $t->tagBind( $tag, '<Button-1>' => [ \&manipulate_link, $tag, 'sunken' ] +); $t->tagBind( $tag, '<ButtonRelease-1>' => [ \&manipulate_link, $tag, 'raised', undef, \&printm +e ] ); $tag++; } else { $t->insert( 'end', $_ ); } } $t->insert( 'end', "\n" ); } MainLoop; sub printme { local ($,) = " "; print "printme:", @_, "\n"; } sub manipulate_link { # manipulate the link as you press the mouse key my ($a) = shift; my ($tag) = shift; my ($relief) = shift; my ($cursor) = shift; my ($after) = shift; # by configuring the relief (to simulate a button press) $a->tagConfigure( $tag, -relief => $relief, -borderwidth => 1 ); # by changing the cursor between hand and xterm $a->configure( -cursor => $cursor ) if ($cursor); # and by scheduling the specified action to run "soon" if ($after) { my ($s) = $a->get( $a->tagRanges($tag) ); $mw->after( 200, [ $after, $a, $s, $tag, @_ ] ) if ($after); } } __DATA__ Hi there. This is text. THis is more text but http://this.is.a/hyperlink in a line. http://this.is.another/hyperlink followed by http://this.is.a.third/hyperlink __END__

        I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://609126]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-07-13 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (247 votes), past polls