Configures Gravity SMTP to use Mailgun via SMTP connection with a fallback option to send out PHP mailer.
// Changes the following variables
from_name="$( wp option get blogname )" # Email from
license="########################" # Gravity SMTP license key
mailgun_from="[email protected]" # Mailgun SMTP send from email
mailgun_user="[email protected]" # Mailgun SMTP username
mailgun_pass="######################" # Mailgun SMTP password
domain=$( wp option get home )
domain=${domain/http:\/\/www./} # removes http://www.
domain=${domain/https:\/\/www./} # removes https://www.
domain=${domain/http:\/\//} # removes https://
domain=${domain/https:\/\//} # removes http://
domain=$( echo $domain | awk '{$1=$1};1' ) # Trims whitespace
read -r -d '' gravitysmtp_config << heredoc
{"debug_log_enabled":"false","setup_wizard_should_display":"false","license_key":"$license","enabled_connector":{"generic":"true","phpmail":"true"},"primary_connector":{"generic":"true","phpmail":"false"},"backup_connector":{"generic":"false","phpmail":"true"}}
heredoc
read -r -d '' gravitysmtp_generic << heredoc
{"host":"smtp.mailgun.org","port":"587","auth":true,"username":"$mailgun_user","password":"$mailgun_pass","from_email":"$mailgun_from","force_from_email":true,"from_name":"$from_name","force_from_name":true,"encryption_type":"tls","auto_tls":true,"use_return_path":false,"activated":true,"configured":true,"enabled":true,"is_primary":true,"is_backup":false}
heredoc
read -r -d '' gravitysmtp_phpmail << heredoc
{"from_email":"wordpress@$domain","force_from_email":true,"from_name":"$from_name","force_from_name":true,"use_return_path":false,"activated":true,"configured":true,"enabled":true,"is_primary":false,"is_backup":true}
heredoc
wp option set gravitysmtp_config "$gravitysmtp_config"
wp option set gravitysmtp_generic "$gravitysmtp_generic"
wp option set gravitysmtp_phpmail "$gravitysmtp_phpmail"
wp plugin activate gravitysmtp
Run it across a fleet
Open the console in CaptainCore Manager, pick the target sites, choose this recipe from the Cookbook picker and press run. The CLI streams each site's output back to the dock.
About the console →