Perl script for sending mail trough Gmail Български

June 19th, 2008Category: My Life

Nothing fancy, just a few prompts and use of Net::SMTP::SSL and Authen::SASL

  1. #!/usr/bin/perl -w
  2. # Send email from Gmail
  3. # Will not work on windows, because of the echo
  4. # for the password. Just uncomment the two
  5. # system lines and should be fine.
  6. # Will wait for EOF (Ctrl+D) for the msg body.
  7. # by GT
  8.  
  9. use Net::SMTP::SSL;
  10.  
  11. my $smtp;
  12. my $username = 'youremail@gmail.com';
  13. my $password;
  14. my @lines;
  15. my $msg = "";
  16. my $to;
  17. my $subject;
  18.  
  19. $smtp = Net::SMTP::SSL->new('smtp.gmail.com', Port => 465, Debug=>1) || die "Cannot connect to server" ;
  20.  
  21. system('stty -echo');
  22. print "Enter password:";
  23. $password = <STDIN>;
  24. chomp $password;
  25. system('stty echo');
  26.  
  27. $smtp->auth($username, $password) || die "Authentication failed";
  28.  
  29. print "\nTo:";
  30. $to = <STDIN>;
  31. chomp $to;
  32. print "Enter subject:";
  33. $subject = <STDIN>;
  34. chomp $subject;
  35. print "Enter message:\n";
  36. @lines = <>;
  37. foreach $line (@lines){
  38. $msg = $msg.$line;
  39. }
  40.  
  41. $smtp->mail($username."\n");
  42. $smtp->to($to."\n");
  43. $smtp->data();
  44. $smtp->datasend("From: ". $username."\n");
  45. $smtp->datasend("To: ".$to."\n");
  46. $smtp->datasend("Subject: ".$subject."\n");
  47. $smtp->datasend("\n");
  48. $smtp->datasend($msg."\n");
  49. $smtp->dataend();
  50. $smtp->quit;
  51.  

Leave a Reply


Georgi’s Blog is proudly powered by WordPress
Постове (RSS) and Коментари (RSS).
Get Firefox! Creative Commons License
22 queries. 1.547 seconds.