Guest User

Untitled

a guest
Sep 24th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use SmtpApiHeader;
  4. use MIME::Entity;
  5. use Net::SMTP;
  6.  
  7. my $hdr = SmtpApiHeader->new;
  8.  
  9. # The list of addresses this message will be sent to
  10. my @toList = ('isaac@example', 'tim@example', 'jose@example');
  11.  
  12. # The names of the recipients
  13. my @nameList = ('Isaac', 'Tim', 'Jose');
  14.  
  15. # Another subsitution variable
  16. my @timeList = ('4pm', '1pm', '2pm');
  17.  
  18. # Set all of the above variables
  19. $hdr->addTo(@toList);
  20. $hdr->addSubVal('-name-', @nameList);
  21. $hdr->addSubVal('-time-', @timeList);
  22.  
  23. # Specify that this is an initial contact message
  24. $hdr->setCategory("initial");
  25.  
  26. # Enable a text footer and set it
  27. $hdr->addFilterSetting('footer', 'enable', 1);
  28. $hdr->addFilterSetting('footer', "text/plain", "Thank you for your business");
  29.  
  30. my $from = 'you@yourdomain.com';
  31.  
  32. # For multiple recipient e-mails, the 'to' address is irrelivant
  33. my $to = 'doesntmatter@nowhere.com';
  34. my $plain = <<EOM;
  35. Hello -name-,
  36.  
  37. Thank you for your interest in our products. We have set up an appointment
  38. to call you at -time- EST to discuss your needs in more detail.
  39.  
  40. Regards,
  41. Fred
  42. EOM
  43.  
  44. my $html = <<EOM;
  45. <html>
  46. <head></head>
  47. <body>
  48.   <p>Hello -name-,<br />
  49.    Thank you for your interest in our products. We have set up an appointment<br />
  50.    to call you at -time- EST to discuss your needs in more detail.<br />
  51.  
  52.     Regards,<br />
  53.     Fred<br />
  54.   </p>
  55. </body>
  56. </html>
  57. EOM
  58.  
  59. # Create the MIME message that will be sent. Check out MIME::Entity on CPAN for more details
  60. my $mime = MIME::Entity->build(Type  => 'multipart/alternative' ,
  61.  
  62. Encoding => '-SUGGEST',
  63. From => $from,
  64. To => $to,
  65. Subject => 'Contact Response for <name> at <time>');
  66.  
  67. # Add the header
  68. $mime->head->add("X-SMTPAPI", $hdr->asJSON);
  69.  
  70. # Add body
  71. $mime->attach(Type => 'text/plain',
  72.                     Encoding =>'-SUGGEST',
  73.                     Data => $plain);
  74.  
  75. $mime->attach(Type => 'text/html',
  76.                     Encoding =>'-SUGGEST',
  77.                     Data => $html);
  78.  
  79. # Login credentials
  80. my $username = 'yourlogin@sendgrid.net';
  81. my $password = "yourpassword";
  82.  
  83. # Open a connection to the SendGrid mail server
  84. my $smtp = Net::SMTP->new('smtp.sendgrid.net',
  85.                     Port=> 25,
  86.                     Timeout => 20,
  87.                     Hello => "yourdomain.com");
  88.  
  89. # Authenticate
  90. $smtp->auth($username, $password);
  91.  
  92. # Send the rest of the SMTP stuff to the server
  93. $smtp->mail($from);
  94. $smtp->to($to);
  95. $smtp->data($mime->stringify);
  96. $smtp->quit();
Add Comment
Please, Sign In to add comment