Guest User

Untitled

a guest
Sep 23rd, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use MIME::Entity;
  5. use Net::SMTP;
  6.  
  7. # from is your email address
  8. # to is who you are sending your email to
  9. # subject will be the subject line of your email
  10. my $from = 'you@yourdomain.com';
  11. my $to = 'person@youaremailing.com';
  12. my $subject = 'Example Perl Email';
  13.  
  14. # Create the MIME message that will be sent. Check out MIME::Entity on CPAN for more details
  15. my $mime = MIME::Entity->build(Type  => 'multipart/alternative',
  16.                             Encoding => '-SUGGEST',
  17.                             From => $from,
  18.                             To => $to,
  19.                             Subject => $subject
  20.                             );
  21. # Create the body of the message (a plain-text and an HTML version).
  22. # text is your plain-text email
  23. # html is your html version of the email
  24. # if the reciever is able to view html emails then only the html
  25. # email will be displayed
  26. my $text = "Hi!\nHow are you?\n";
  27. my $html = <<EOM;
  28. <html>
  29.   <head></head>
  30.   <body>
  31.     <p>Hi!<br>
  32.        How are you?<br>
  33.     </p>
  34.   </body>
  35. </html>
  36. EOM
  37.  
  38. # attach the body of the email
  39. $mime->attach(Type => 'text/plain',
  40.             Encoding =>'-SUGGEST',
  41.             Data => $text);
  42.  
  43. $mime->attach(Type => 'text/html',
  44.             Encoding =>'-SUGGEST',
  45.             Data => $html);
  46.  
  47. # Login credentials
  48. my $username = 'yourlogin@sendgrid.net';
  49. my $password = "yourpassword";
  50.  
  51. # Open a connection to the SendGrid mail server
  52. my $smtp = Net::SMTP->new('smtp.sendgrid.net',
  53.                         Port=> 587,
  54.                         Timeout => 20,
  55.                         Hello => "yourdomain.com");
  56.  
  57. # Authenticate
  58. $smtp->auth($username, $password);
  59.  
  60. # Send the rest of the SMTP stuff to the server
  61. $smtp->mail($from);
  62. $smtp->to($to);
  63. $smtp->data($mime->stringify);
  64. $smtp->quit();
Add Comment
Please, Sign In to add comment