You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the request to the API failed for any reason a `SendGridError` is thrown, which has an `errors` property that contains an array of errors returned by the API.
67
+
68
+
Simply ensure you catch errors thrown like any other throwing function.
69
+
70
+
```swift
71
+
importSendGridKit
72
+
73
+
do {
74
+
tryawait sendGridClient.send(email: email)
75
+
} catchlet error asSendGridError {
76
+
print(error)
77
+
}
78
+
```
79
+
64
80
### Email Validation API
65
81
66
-
SendGridKit supports SendGrid's Email Validation API, which helps verify the validity of email addresses before sending:
82
+
SendGridKit supports SendGrid's [Email Address Validation API](https://www.twilio.com/docs/sendgrid/ui/managing-contacts/email-address-validation), which provides detailed information on the validity of email addresses.
67
83
68
84
```swift
69
85
importSendGridKit
@@ -78,18 +94,18 @@ do {
78
94
let validationResponse =tryawait sendGridClient.validateEmail(validationRequest)
79
95
80
96
// Check if the email is valid
81
-
if validationResponse.result.verdict == .valid {
82
-
print("Email is valid with score: \(validationResponse.result.score)")
97
+
if validationResponse.result?.verdict == .valid {
98
+
print("Email is valid with score: \(validationResponse.result?.score)")
83
99
} else {
84
-
print("Email is invalid: \(validationResponse.result.reason??"Unknown reason")")
100
+
print("Email is invalid")
85
101
}
86
102
87
103
// Access detailed validation information
88
-
if validationResponse.checks.disposable {
89
-
print("Warning: This is a disposable email address")
104
+
if validationResponse.result?.checks?.domain?.isSuspectedDisposableAddress ??true {
105
+
print("Warning: This is probably a disposable email address")
90
106
}
91
107
92
-
if validationResponse.checks.roleAccount {
108
+
if validationResponse.result?.checks?.localPart?.isSuspectedRoleAddress {
93
109
print("Note: This is a role-based email address")
94
110
}
95
111
} catch {
@@ -99,7 +115,7 @@ do {
99
115
100
116
#### Bulk Email Validation API
101
117
102
-
For validating multiple email addresses at once, SendGridKit provides access to SendGrid's Bulk Email Validation API. This requires uploading a CSV file with email addresses:
118
+
For validating multiple email addresses at once, SendGridKit provides access to SendGrid's Bulk Email Address Validation API. This requires uploading a CSV file with email addresses:
103
119
104
120
```swift
105
121
importSendGridKit
@@ -110,55 +126,37 @@ let sendGridClient = SendGridEmailValidationClient(httpClient: .shared, apiKey:
If the request to the API failed for any reason a `SendGridError` is thrown, which has an `errors` property that contains an array of errors returned by the API.
153
-
154
-
Simply ensure you catch errors thrown like any other throwing function.
0 commit comments