Home / Admin / Using an Office 365 GCC or DoD email address
Duplicate Snippet

Embed Snippet on Your Site

Using an Office 365 GCC or DoD email address

For security measures, Government Community Cloud (GCC) and U.S. Department of Defense (DoD) accounts typically use the .us domain extension instead of .com. This snippet will allow you to set up these types of accounts.

Code Preview
php
<?php
/* Using an Office 365 GCC or DoD email address  
 * 
 * Original doc: https://wpmailsmtp.com/docs/how-to-set-up-the-outlook-mailer-in-wp-mail-smtp/
*/
function theme_prefix_enable_gcc_high_and_dod_compatibility( $country_code ) {
 
    add_filter( 'wp_mail_smtp_pro_providers_outlook_auth_authorize_url', function ( $url ) use ( $country_code ) {
        return str_replace( 'microsoftonline.com', 'microsoftonline.' . $country_code, $url );
    } );
 
    add_filter( 'wp_mail_smtp_pro_providers_outlook_auth_access_token_url', function ( $url ) use ( $country_code ) {
        return str_replace( 'microsoftonline.com', 'microsoftonline.' . $country_code, $url );
    } );
 
    add_filter( 'wp_mail_smtp_pro_providers_outlook_auth_resource_owner_details_url', function ( $url ) use ( $country_code ) {
        return str_replace( 'microsoft.com', 'microsoft.' . $country_code, $url );
    } );
 
	add_filter( 'wp_mail_smtp_pro_providers_outlook_auth_get_scopes', function ( $scopes ) use ( $country_code ) {
		return array_map( function ( $url ) use ( $country_code ) {
			return str_replace( 'microsoft.com', 'microsoft.' . $country_code, $url );
		}, $scopes );
	} );
 
	add_filter( 'wp_mail_smtp_pro_providers_outlook_mailer_api_url', function ( $url ) use ( $country_code ) {
		return str_replace( 'microsoft.com', 'microsoft.' . $country_code, $url );
	} );
}
 
// Define country code as first parameter.
// If using a different a different country, replace 'us' with your 2 letter country code.
// To find your country code, please visit: https://www.iban.com/country-codes
theme_prefix_enable_gcc_high_and_dod_compatibility( 'us' );

Comments

Add a Comment