Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. Subject: "Hello. Текст"
  2. Body: "test email. Русский текст"
  3.  
  4. Subject: "Hello. Текст"
  5. Body: "test email. Русский текст"
  6.  
  7. #!/usr/bin/perl
  8.  
  9. use utf8;
  10. use strict;
  11. use warnings;
  12.  
  13. use Email::Sender::Simple qw(sendmail);
  14. use Email::Sender::Transport::SMTP ();
  15. use Email::Simple ();
  16. use MIME::Base64 qw( encode_base64 );
  17. use open ':std', ':encoding(UTF-8)';
  18.  
  19. sub send_email
  20. {
  21. my $email_from = shift;
  22. my $email_to = shift;
  23. my $subject = shift;
  24. my $message = shift;
  25.  
  26. my $smtpserver = 'smtp.gmail.com';
  27. my $smtpport = 465;
  28. my $smtpuser = 'user@gmail.com';
  29. my $password = 'secret';
  30.  
  31. my $transport = Email::Sender::Transport::SMTP->new({
  32. host => $smtpserver,
  33. port => $smtpport,
  34. sasl_username => $smtpuser,
  35. sasl_password => $password,
  36. debug => 1,
  37. ssl => 1,
  38. });
  39.  
  40. my $email = Email::Simple->create(
  41. header => [
  42. To => $email_to,
  43. From => $email_from,
  44. Subject => $subject,
  45. ],
  46. body => $message,
  47. );
  48.  
  49. $email->header_set( 'Content-Type' => 'text/html' );
  50. $email->header_set( 'charset' => 'UTF-8' );
  51. sendmail($email, { transport => $transport });
  52. }
  53.  
  54. my $body = Encode::encode('utf-8', 'test email. Русский текст');
  55. my $subject = Encode::encode('utf-8', 'Hello. Текст');
  56. send_email('user@gmail.com', 'user@gmail.com', $subject, $body);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement