Advertisement
hakonhagland

Source code using Authen::SASL::Perl

Sep 27th, 2016
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.88 KB | None | 0 0
  1. #! /usr/bin/env perl
  2.  
  3. use feature qw(say);
  4. use strict;
  5. use warnings;
  6. use utf8;
  7.  
  8. use Authen::SASL qw(Perl);
  9. use Net::SMTP 3.0;
  10.  
  11. my $smtp = Net::SMTP->new(
  12.     'smtp.gmail.com',
  13.     SSL=>1,
  14.     Timeout => 20,
  15.     Debug   => 1,
  16. );
  17. die "Initialization failed: $!" if !defined $smtp;
  18.  
  19. my $sender = my $user = 'hakon.hagland@gmail.com';
  20. my $password = '????';
  21. say "Trying to authenticate..";
  22. my $auth_res = $smtp->auth( $user, $password);
  23. say "could not authenticate\n" if !$auth_res;
  24.  
  25. my $receiver = 'hakon.hagland@gmail.com';
  26. $smtp->mail( $sender );
  27. $smtp->to( $receiver );
  28. $smtp->data();
  29. $smtp->datasend( "To: $receiver\n" );
  30. $smtp->datasend( "From: $sender\n" );
  31. $smtp->datasend( "Content-Type: text/html\n" );
  32. $smtp->datasend( "Subject: Testing Net::SMTP" );
  33. $smtp->datasend( "\n" );
  34. $smtp->datasend( 'The body of the email' );
  35. $smtp->dataend();
  36. $smtp->quit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement