How to validate your email using SSJS?
<script runat="server">
Platform.Load("Core", "1");
try {
// Function to retrieve access token
function getAccessToken() {
var tokenUrl = 'https://{Subdomain}.auth.marketingcloudapis.com/v2/token';
var contentType = 'application/json';
var tokenPayload = {
"grant_type": "client_credentials",
"client_id": "your client id",
"client_secret": "your client scerect",
"account_id": "mid"
};
var tokenResponse = HTTP.Post(tokenUrl, contentType, Stringify(tokenPayload));
var tokenStatusCode = tokenResponse.StatusCode;
var tokenObj = Platform.Function.ParseJSON(tokenResponse.Response + '');
if (tokenStatusCode === 200 && tokenObj && tokenObj.access_token) {
return tokenObj.access_token;
} else {
throw "Failed to obtain access token.";
}
}
var accessToken = getAccessToken();
var authorizationHeader = 'Bearer ' + accessToken;
var content = [0];
var emailValidationPayload = {
"email": "xyz@gmail.com",
"validators": [ "SyntaxValidator", "MXValidator", "ListDetectiveValidator" ]
}
var postResponse = Platform.Function.HTTPPost('https://{Subdomain}.rest.marketingcloudapis.com/address/v1/validateEmail','application/json',Stringify(emailValidationPayload),['Authorization'],[authorizationHeader],content);
Platform.Response.Write(content[0]);
} catch (ex) {
Platform.Response.Write("Error message: " + ex);
}
</script>