Skip to content

Instantly share code, notes, and snippets.

@ianwinter
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianwinter/795c0a3e964a4074348c to your computer and use it in GitHub Desktop.
Save ianwinter/795c0a3e964a4074348c to your computer and use it in GitHub Desktop.
Quick script to call Dyn's API to (optionally) remove Postini MX records and add lowercased Google Mail MX records.
require 'dyn-rb'
# usage: ruby ./lowercase_google_mx.rb domain.com
# 1: set up the connection
dyn = Dyn::Traffic::Client.new('CUSTOMER_NAME', 'USERNAME', 'PASSWORD')
# 2: set the zone
zone = ARGV[0].to_s
dyn.zone = zone
puts "replacing for #{zone}"
# 3: remove MX records
dyn.mx.get(zone).map do |r|
if r.rdata["exchange"].include? "ASPMX.L.GOOGLE.COM"
dyn.mx.fqdn(zone).record_id(r.record_id).delete
end
# [OPTIONAL] if you're moving away from postini you can also bin off those records
# if r.rdata["exchange"].include? "psmtp"
# dyn.mx.fqdn(zone).record_id(r.record_id).delete
# end
end
puts ".. deleted"
# 4: create an MX record
dyn.mx.fqdn(zone).exchange("aspmx.l.google.com.").preference(1).ttl(3600).save()
dyn.mx.fqdn(zone).exchange("alt1.aspmx.l.google.com.").preference(5).ttl(3600).save()
dyn.mx.fqdn(zone).exchange("alt2.aspmx.l.google.com.").preference(5).ttl(3600).save()
dyn.mx.fqdn(zone).exchange("alt3.aspmx.l.google.com.").preference(10).ttl(3600).save()
dyn.mx.fqdn(zone).exchange("alt4.aspmx.l.google.com.").preference(10).ttl(3600).save()
puts ".. added"
# 5: publish the changes
dyn.zone.publish
puts ".. published!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment