Qamba Knowledge Base

Mailgun SMTP password too long for printer

You are here:

Please Note:
Unlike many of the articles on this site, this article is written for “IT people” and relates to technical subject matter.
Only follow the below info if suitable to your specific situation and you understand and accept all risk.

You would think in 2021, almost any device handling passwords would not put arbitrary limits on how long a password can be. If you, like us use Mailgun to enable consistent and reliable STMP from printers for our clients, you may have run into this problem with Mailgun and printer SMTP login details.

Mailgun by default generates a nice ridiculously secure password. For some reason, some old (and some new) printers limit the length of password that can be entered for SMTP, often to only 32 characters(or even less…).

Mailgun does not let you set shortened password via their website. However, you can through their API.
It turns out a few people have encountered this issue, and I do hope eventually Mailgun will provide multiple length/format options for passwords, but for now we can make use of their API.

Below is some easy to edit PowerShell code,
you can use this to set a custom user with a specific password for any domain on your MailGun account.

  1. Grab your API key from your account settings page on Mailgun. (make sure to only store this securely).
  2. Copy the below code into notepad,
  3. Add your details in the section marked below. Take caution to leave the ‘quotes’ where they are.
  4. Copy your update version of the script and paste it into PowerShell and hit enter.
  5. Check your Mailgun account and confirm the account exists there. If the user email already exists the password will be updated.
  6. Use your credentials.

#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——-
#Account API Key, Found in the settings page of your mailgun account. Keep this secure. Do not save it with this script.
$mailgunAPIkey = “key-000000000000000000”
#Senders Domain Name
$Domain = “domainname.com.au”
#SMTP username and password you want to set, make sure to set a secure password.
$userlogonemail = ‘EmailAddress@domainname.com.au’
$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
#
#

 

Table of Contents