Skip to content

Commit 588c067

Browse files
feat: add spam, bounce and unsubscribe bypass management filters (#1065)
1 parent 61ecad4 commit 588c067

14 files changed

+930
-200
lines changed

USAGE.md

+13
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,9 @@ This endpoint allows you to send the email over Twilio SendGrid's v3 Web API, th
21752175
* Top level parameters are referred to as "global".
21762176
* Individual fields within the personalizations array will override any other global, or message level, parameters that are defined outside of personalizations.
21772177

2178+
* Note: bypass_bounce_management, bypass_spam_management, and bypass_unsubscribe_management cannot
2179+
* be combined with bypass_list_management
2180+
21782181
For an overview of the v3 Mail Send endpoint, please visit our [v3 API Reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html)
21792182

21802183
For more detailed information about how to use the v3 Mail Send endpoint, please visit our [Classroom](https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/index.html).
@@ -2230,9 +2233,19 @@ $request_body = json_decode('{
22302233
"email": "[email protected]",
22312234
"enable": true
22322235
},
2236+
"bypass_bounce_management": {
2237+
"enable": true
2238+
},
22332239
"bypass_list_management": {
22342240
"enable": true
22352241
},
2242+
"bypass_spam_management": {
2243+
"enable": true
2244+
},
2245+
"bypass_unsubscribe_management": {
2246+
"enable": true
2247+
},
2248+
22362249
"footer": {
22372250
"enable": true,
22382251
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",

USE_CASES.md

+23
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,12 @@ $email->setIpPoolName("23");
450450

451451
// Mail Settings
452452
$email->setBccSettings(true, "[email protected]");
453+
// Note: Bypass Spam, Bounce, and Unsubscribe management cannot
454+
// be combined with Bypass List Management
455+
$email->enableBypassBounceManagement();
453456
$email->enableBypassListManagement();
457+
$email->enableBypassSpamManagement();
458+
$email->enableBypassUnsubscribeManagement();
454459
//$email->disableBypassListManagement();
455460
$email->setFooter(true, "Footer", "<strong>Footer</strong>");
456461
$email->enableSandBoxMode();
@@ -498,7 +503,10 @@ use SendGrid\Mail\Attachment;
498503
use SendGrid\Mail\BatchId;
499504
use SendGrid\Mail\Bcc;
500505
use SendGrid\Mail\BccSettings;
506+
use SendGrid\Mail\BypassBounceManagement;
501507
use SendGrid\Mail\BypassListManagement;
508+
use SendGrid\Mail\BypassSpamManagement;
509+
use SendGrid\Mail\BypassUnsubscribeManagement;
502510
use SendGrid\Mail\Category;
503511
use SendGrid\Mail\Cc;
504512
use SendGrid\Mail\ClickTracking;
@@ -712,9 +720,24 @@ $mail_settings = new MailSettings();
712720
$mail_settings->setBccSettings(
713721
new BccSettings(true, "[email protected]")
714722
);
723+
724+
// Note: Bypass Spam, Bounce, and Unsubscribe management cannot
725+
// be combined with Bypass List Management
726+
$mail_settings->setBypassBounceManagement(
727+
new BypassBounceManagement(true)
728+
);
729+
$mail_settings->setBypassSpamManagement(
730+
new BypassSpamManagement(true)
731+
);
732+
$mail_settings->setBypassUnsubscribeManagement(
733+
new BypassUnsubscribeManagement(true)
734+
);
735+
736+
// OR
715737
$mail_settings->setBypassListManagement(
716738
new BypassListManagement(true)
717739
);
740+
718741
$mail_settings->setFooter(
719742
new Footer(true, "Footer", "<strong>Footer</strong>")
720743
);

examples/helpers/mail/example.php

+14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
use SendGrid\Mail\MailSettings;
2121
use SendGrid\Mail\BccSettings;
2222
use SendGrid\Mail\SandBoxMode;
23+
use SendGrid\Mail\BypassBounceManagement;
2324
use SendGrid\Mail\BypassListManagement;
25+
use SendGrid\Mail\BypassSpamManagement;
26+
use SendGrid\Mail\BypassUnsubscribeManagement;
2427
use SendGrid\Mail\Footer;
2528
use SendGrid\Mail\SpamCheck;
2629
use SendGrid\Mail\TrackingSettings;
@@ -158,9 +161,20 @@ function kitchenSink()
158161
$sandbox_mode = new SandBoxMode();
159162
$sandbox_mode->setEnable(true);
160163
$mail_settings->setSandboxMode($sandbox_mode);
164+
// Note: Bypass Spam, Bounce, and Unsubscribe management cannot
165+
// be combined with Bypass List Management
166+
$bypass_bounce_management = new BypassBounceManagement();
167+
$bypass_bounce_management->setEnable(true);
168+
$mail_settings->setBypassBounceManagement($bypass_bounce_management);
161169
$bypass_list_management = new BypassListManagement();
162170
$bypass_list_management->setEnable(true);
163171
$mail_settings->setBypassListManagement($bypass_list_management);
172+
$bypass_spam_management = new BypassSpamManagement();
173+
$bypass_spam_management->setEnable(true);
174+
$mail_settings->setBypassSpamManagement($bypass_spam_management);
175+
$bypass_unsubscribe_management = new BypassUnsubscribeManagement();
176+
$bypass_unsubscribe_management->setEnable(true);
177+
$mail_settings->setBypassUnsubscribeManagement($bypass_unsubscribe_management);
164178
$footer = new Footer();
165179
$footer->setEnable(true);
166180
$footer->setText("Footer Text");

examples/mail/mail.php

+9
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,18 @@
8686
"email": "[email protected]",
8787
"enable": true
8888
},
89+
"bypass_bounce_management": {
90+
"enable": true
91+
},
8992
"bypass_list_management": {
9093
"enable": true
9194
},
95+
"bypass_spam_management": {
96+
"enable": true
97+
},
98+
"bypass_unsubscribe_management": {
99+
"enable": true
100+
},
92101
"footer": {
93102
"enable": true,
94103
"html": "<p>Thanks</br>The Twilio SendGrid Team</p>",

lib/mail/BypassBounceManagement.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* This helper builds the BypassBounceManagement object for a /mail/send API call
4+
*/
5+
6+
namespace SendGrid\Mail;
7+
8+
use SendGrid\Helper\Assert;
9+
10+
/**
11+
* This class is used to construct a BypassBounceManagement object for
12+
* the /mail/send API call
13+
*
14+
* Allows you to bypass the bounce list to ensure that the email is delivered to recipients.
15+
* Spam report and unsubscribe lists will still be checked; addresses on these other lists
16+
* will not receive the message.
17+
*
18+
* This filter cannot be combined with the bypass_list_management filter.
19+
*
20+
* @package SendGrid\Mail
21+
*/
22+
class BypassBounceManagement implements \JsonSerializable
23+
{
24+
/** @var $enable bool Indicates if this setting is enabled */
25+
private $enable;
26+
27+
/**
28+
* Optional constructor
29+
*
30+
* @param bool|null $enable Indicates if this setting is enabled
31+
* @throws \SendGrid\Mail\TypeException
32+
*/
33+
public function __construct($enable = null)
34+
{
35+
if (isset($enable)) {
36+
$this->setEnable($enable);
37+
}
38+
}
39+
40+
/**
41+
* Update the enable setting on a BypassBounceManagement object
42+
*
43+
* @param bool $enable Indicates if this setting is enabled
44+
*
45+
* @throws \SendGrid\Mail\TypeException
46+
*/
47+
public function setEnable($enable)
48+
{
49+
Assert::boolean($enable, 'enable');
50+
51+
$this->enable = $enable;
52+
}
53+
54+
/**
55+
* Retrieve the enable setting on a BypassBounceManagement object
56+
*
57+
* @return bool
58+
*/
59+
public function getEnable()
60+
{
61+
return $this->enable;
62+
}
63+
64+
/**
65+
* Return an array representing a BypassBounceManagement object for
66+
* the SendGrid API
67+
*
68+
* @return null|array
69+
*/
70+
public function jsonSerialize()
71+
{
72+
return array_filter(
73+
[
74+
'enable' => $this->getEnable()
75+
],
76+
function ($value) {
77+
return $value !== null;
78+
}
79+
) ?: null;
80+
}
81+
}

lib/mail/BypassSpamManagement.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* This helper builds the BypassSpamManagement object for a /mail/send API call
4+
*/
5+
6+
namespace SendGrid\Mail;
7+
8+
use SendGrid\Helper\Assert;
9+
10+
/**
11+
* This class is used to construct a BypassSpamManagement object for
12+
* the /mail/send API call
13+
*
14+
* Allows you to bypass the spam report list to ensure that the email is delivered to recipients.
15+
* Bounce and unsubscribe lists will still be checked; addresses on these other lists will not
16+
* receive the message.
17+
*
18+
* This filter cannot be combined with the bypass_list_management filter.
19+
*
20+
* @package SendGrid\Mail
21+
*/
22+
class BypassSpamManagement implements \JsonSerializable
23+
{
24+
/** @var $enable bool Indicates if this setting is enabled */
25+
private $enable;
26+
27+
/**
28+
* Optional constructor
29+
*
30+
* @param bool|null $enable Indicates if this setting is enabled
31+
* @throws \SendGrid\Mail\TypeException
32+
*/
33+
public function __construct($enable = null)
34+
{
35+
if (isset($enable)) {
36+
$this->setEnable($enable);
37+
}
38+
}
39+
40+
/**
41+
* Update the enable setting on a BypassSpamManagement object
42+
*
43+
* @param bool $enable Indicates if this setting is enabled
44+
*
45+
* @throws \SendGrid\Mail\TypeException
46+
*/
47+
public function setEnable($enable)
48+
{
49+
Assert::boolean($enable, 'enable');
50+
51+
$this->enable = $enable;
52+
}
53+
54+
/**
55+
* Retrieve the enable setting on a BypassSpamManagement object
56+
*
57+
* @return bool
58+
*/
59+
public function getEnable()
60+
{
61+
return $this->enable;
62+
}
63+
64+
/**
65+
* Return an array representing a BypassSpamManagement object for
66+
* the SendGrid API
67+
*
68+
* @return null|array
69+
*/
70+
public function jsonSerialize()
71+
{
72+
return array_filter(
73+
[
74+
'enable' => $this->getEnable()
75+
],
76+
function ($value) {
77+
return $value !== null;
78+
}
79+
) ?: null;
80+
}
81+
}
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* This helper builds the BypassUnsubscribeManagement object for a /mail/send API call
4+
*/
5+
6+
namespace SendGrid\Mail;
7+
8+
use SendGrid\Helper\Assert;
9+
10+
/**
11+
* This class is used to construct a BypassUnsubscribeManagement object for
12+
* the /mail/send API call
13+
*
14+
* Allows you to bypass the global unsubscribe list to ensure that the email is delivered
15+
* to recipients. Bounce and spam report lists will still be checked; addresses on these
16+
* other lists will not receive the message. This filter applies only to global unsubscribes
17+
* and will not bypass group unsubscribes.
18+
*
19+
* This filter cannot be combined with the bypass_list_management filter.
20+
*
21+
* @package SendGrid\Mail
22+
*/
23+
class BypassUnsubscribeManagement implements \JsonSerializable
24+
{
25+
/** @var $enable bool Indicates if this setting is enabled */
26+
private $enable;
27+
28+
/**
29+
* Optional constructor
30+
*
31+
* @param bool|null $enable Indicates if this setting is enabled
32+
* @throws \SendGrid\Mail\TypeException
33+
*/
34+
public function __construct($enable = null)
35+
{
36+
if (isset($enable)) {
37+
$this->setEnable($enable);
38+
}
39+
}
40+
41+
/**
42+
* Update the enable setting on a BypassUnsubscribeManagement object
43+
*
44+
* @param bool $enable Indicates if this setting is enabled
45+
*
46+
* @throws \SendGrid\Mail\TypeException
47+
*/
48+
public function setEnable($enable)
49+
{
50+
Assert::boolean($enable, 'enable');
51+
52+
$this->enable = $enable;
53+
}
54+
55+
/**
56+
* Retrieve the enable setting on a BypassUnsubscribeManagement object
57+
*
58+
* @return bool
59+
*/
60+
public function getEnable()
61+
{
62+
return $this->enable;
63+
}
64+
65+
/**
66+
* Return an array representing a BypassUnsubscribeManagement object for
67+
* the SendGrid API
68+
*
69+
* @return null|array
70+
*/
71+
public function jsonSerialize()
72+
{
73+
return array_filter(
74+
[
75+
'enable' => $this->getEnable()
76+
],
77+
function ($value) {
78+
return $value !== null;
79+
}
80+
) ?: null;
81+
}
82+
}

0 commit comments

Comments
 (0)