Categories and Unique Arguments will be stored as a "Not PII" field and may be used for counting or other operations as SendGrid runs its systems. These fields generally cannot be redacted or removed. You should take care not to place PII in this field. SendGrid does not treat this data as PII, and its value may be visible to SendGrid employees, stored long-term, and may continue to be stored after you've left SendGrid's platform.
_88# !/usr/bin/perl_88_88# Version 1.0_88# Last Updated 6/22/2009_88use strict;_88package SmtpApiHeader;_88use JSON;_88_88sub new_88{_88my $self = shift;_88my @a = ();_88$self = { 'data' => { }};_88bless($self);_88return $self;_88}_88_88sub addTo_88{_88my $self = shift;_88my @to = @_;_88push(@{$self->{data}->{to}}, @to);_88}_88_88sub addSubVal_88{_88my $self = shift;_88my $var = shift;_88my @val = @_;_88_88if (!defined($self->{data}->{sub}->{$var}))_88{_88 $self->{data}->{sub}->{$var} = ();_88}_88push(@{$self->{data}->{sub}->{$var}}, @val);_88}_88_88sub setUniqueArgs_88{_88my $self = shift;_88my $val = shift;_88if (ref($val) eq 'HASH')_88{_88 $self->{data}->{unique_args} = $val;_88}_88}_88_88sub setCategory_88{_88my $self = shift;_88my $cat = shift;_88$self->{data}->{category} = $cat;_88}_88_88sub addFilterSetting_88{_88my $self = shift;_88my $filter = shift;_88my $setting = shift;_88my $val = shift;_88if (!defined($self->{data}->{filters}->{$filter}))_88{_88 $self->{data}->{filters}->{$filter} = {};_88}_88if (!defined($self->{data}->{filters}->{$filter}->{settings}))_88{_88 $self->{data}->{filters}->{$filter}->{settings} = {};_88}_88$self->{data}->{filters}->{$filter}->{settings}->{$setting} = $val;_88}_88_88sub asJSON_88{_88my $self = shift;_88my $json = JSON->new;_88$json->space_before(1);_88$json->space_after(1);_88return $json->encode($self->{data});_88}_88_88sub as_string_88{_88my $self = shift;_88my $json = $self->asJSON;_88$json =~ s/(.{1,72})(\s)/$1\n /g;_88my $str = "X-SMTPAPI: $json";_88return $str;_88}
_129# !/usr/bin/perl_129use SmtpApiHeader;_129_129my @receiver = ('kyle','bob','someguy');_129_129my $hdr = SmtpApiHeader->new;_129_129my $time = '1pm';_129my $name = 'kyle';_129_129$hdr->addFilterSetting('subscriptiontrack', 'enable', 1);_129$hdr->addFilterSetting('twitter', 'enable', 1); #please check the apps available for your current package at https://sendgrid.com/pricing_129$hdr->addTo(@receiver);_129$hdr->addTo('kyle2');_129_129$hdr->addSubVal('-time-', $time);_129_129$hdr->addSubVal('-name-', $time);_129$hdr->setUniqueArgs({'test'=>1, 'foo'=>2});_129_129print $hdr->as_string;_129_129print "\n";_129</code>_129_129## Full Perl Example_129 <p>The following code builds a MIME mail message demonstrating all the portions of the SMTP API protocol. To use this example, you will need to have the following perl modules installed:</p>_129<ul class="regular">_129 <li>MIME::Entity</li>_129 <li>Authen::SASL</li>_129 <li>JSON</li>_129</ul>_129<code>_129# !/usr/bin/perl_129use strict;_129use SmtpApiHeader;_129use MIME::Entity;_129use Net::SMTP;_129_129my $hdr = SmtpApiHeader->new;_129_129# The list of addresses this message will be sent to_129my @toList = ('isaac@example', 'tim@example', 'jose@example');_129_129# The names of the recipients_129my @nameList = ('Isaac', 'Tim', 'Jose');_129_129# Another substitution variable_129my @timeList = ('4pm', '1pm', '2pm');_129_129# Set all of the above variables_129$hdr->addTo(@toList);_129$hdr->addSubVal('-name-', @nameList);_129$hdr->addSubVal('-time-', @timeList);_129_129# Specify that this is an initial contact message_129$hdr->setCategory("initial");_129_129# Enable a text footer and set it_129$hdr->addFilterSetting('footer', 'enable', 1);_129$hdr->addFilterSetting('footer', "text/plain", "Thank you for your business");_129_129my $from = 'you@yourdomain.com';_129_129# For multiple recipient emails, the 'to' address is irrelevant_129my $to = 'example@example.com';_129my $plain = <<EOM;_129Hello -name-,_129_129Thank you for your interest in our products. We have set up an appointment_129to call you at -time- EST to discuss your needs in more detail._129_129Regards,_129Fred_129EOM_129_129my $html = <<EOM;_129<html>_129<head></head>_129<body>_129<p>Hello -name-,<br />_129 Thank you for your interest in our products. We have set up an appointment<br />_129 to call you at -time- EST to discuss your needs in more detail.<br />_129_129 Regards,<br />_129 Fred<br />_129</p>_129</body>_129</html>_129EOM_129_129# Create the MIME message that will be sent. Check out MIME::Entity on CPAN for more details_129my $mime = MIME::Entity->build(Type => 'multipart/alternative' ,_129_129Encoding => '-SUGGEST',_129From => $from,_129To => $to,_129Subject => 'Contact Response for <name> at <time>');_129_129# Add the header_129$mime->head->add("X-SMTPAPI", $hdr->asJSON);_129_129# Add body_129$mime->attach(Type => 'text/plain',_129 Encoding =>'-SUGGEST',_129 Data => $plain);_129_129$mime->attach(Type => 'text/html',_129 Encoding =>'-SUGGEST',_129 Data => $html);_129_129# Login credentials_129my $username = 'apikey';_129my $api_key = "your_api_key";_129_129# Open a connection to the SendGrid mail server_129my $smtp = Net::SMTP->new('smtp.sendgrid.net',_129 Port=> 587,_129 Timeout => 20,_129 Hello => "yourdomain.com");_129_129# Authenticate_129$smtp->auth($username, $api_key);_129_129# Send the rest of the SMTP stuff to the server_129$smtp->mail($from);_129$smtp->to($to);_129$smtp->data($mime->stringify);_129$smtp->quit();