-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovh_mail_alias_rm.py
49 lines (40 loc) · 1.39 KB
/
ovh_mail_alias_rm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- encoding: utf-8 -*-
import config # config file
import os
import sys
# Make sure we are in script's directory for ovh module to find its ovh.conf file
os.chdir(os.path.dirname(os.path.realpath(__file__)))
# OVH API python wrapper
import ovh
# API endpoint for email redirection
base_api_endpoint = "/email/domain/%s/redirection" % config.domain
# Ask for redir ID if not provided through args
if len(sys.argv) < 2:
redir_id = input("Enter redirection ID:\n")
else:
redir_id = sys.argv[1]
# Create wrapper
client = ovh.Client()
try:
# Try to find the ID
redir_details = client.get("%s/%s" % (base_api_endpoint, redir_id))
# Ask for confirmation
print("")
print("Delete the following alias:")
print("ID : %s" % redir_id)
print("From : %s" % redir_details['from'])
print("To : %s" % redir_details['to'])
print("")
input("Continue (ENTER or CTRL+C to cancel)?")
print("")
print("Deleting...")
result = client.delete("%s/%s" % (base_api_endpoint, redir_id))
# Check if deletion was real
try:
client.get("%s/%s" % (base_api_endpoint, redir_id))
print("Something went wrong, the alias still seems to exists...")
except ovh.exceptions.ResourceNotFoundError as e:
print("Alias deleted!")
except ovh.exceptions.ResourceNotFoundError as e:
print("Error: alias %s does not exists!" % redir_id)
print("")