Skip to content

Instantly share code, notes, and snippets.

@drewgates
Created March 21, 2022 17:38
Show Gist options
  • Save drewgates/d96428e8615ffc29573d2edf2aba1fd2 to your computer and use it in GitHub Desktop.
Save drewgates/d96428e8615ffc29573d2edf2aba1fd2 to your computer and use it in GitHub Desktop.
#The below script/code is provided without warranty.
#Only use if you clearly understand what you are doing, and accept all risk.
#This advise applies to ALL script/code you find on the internet.
#Tested on Powershell 5.0 on Windows 10.
#
#---------ADD YOUR INFORMATION HERE-------
#HTTP webhook signing key, Found in the settings page of your mailgun account. Keep this secure. Do not save it with this script.
#https://app.mailgun.com/app/account/security/api_keys
$mailgunAPIkey = "key-000000000000000000"
#Senders Domain Name
$Domain = "mg.example.com"
#SMTP username and password you want to set, make sure to set a secure password.
$userlogonemail = 'EmailAddress@mg.example.com'
$userlogonpass= 'SET THIS TO SOMETHING SECURE'
#----------------------------------------
#Default API user for mailgun, don't change.
$user = "api"
#Magic formatting to get the APIkey into the right format.
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$mailgunAPIkey)))
$headers = @{
Authorization = "Basic $base64AuthInfo"
}
#API url required, can be modified to use other features only available in the api
$url = "https://api.mailgun.net/v3/domains/$domain/credentials"
$body = @{
login = $userlogonemail;
password = $userlogonpass;
}
#This last command uses all the above information and submits the account.
#After it runs you will see the account listed in the mailgun website under that domain.
Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment